当前位置:网站首页>【C语言对数据文件的顺序读写】
【C语言对数据文件的顺序读写】
2022-07-16 19:15:00 【书中藏着宇宙】
| 函数名 | 功能 | 返回值 |
fgetc() | 从fp指向的文件中读入一个字符 | 成功:返回读入的字符 失败:返回EOF |
| putc() | 把字符ch写到文件指针变量fp指向的文件中 | 成功:返回值输出的字符 失败:返回EOF |
备注:EOF是C语言里面的常用失败返回值(-1)
/*对于文件的读写*/
#include <stdio.h>
#include <stdlib.h>
void main()
{ FILE *fp;//建立一个文件指针
char ch,filename[15];
printf("请你输入文件名:");
scanf("%s",filename);//输入文件名
getchar();
if(fp=fopen(filename,"w")==NULL)
{
printf("文件打开错误,可能不存在\n");
exit(0);
}
printf("请你输入一个内容,以#结束\n");
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
putchar(ch);
ch=getchar();
}
fclose(fp);
putchar(10);
return 0;
}输出结果:
边栏推荐
- Installing MySQL database on Linux server (detailed tutorial)
- Spatial attribute overview C language
- markdown 数学公式 任意符号 存在符号
- ES6-新增的数组方法之最常用的几种 map(),filter(),reduce(),forEach(),
- (笔记整理未完成)【图论:最小生成树】
- 8大主流OA办公软件比拼,传统VS新秀你PICK谁?
- 阿普奇 ABOX-700 工控机 MinipiceCAN卡在电力巡检机器人中的应用
- Application of Apache E8 industrial computer minipicecan card in Construction Robot
- 【微信小程序】progress(93/100)
- Current limiting configuration of freeswitch
猜你喜欢

Phabricator Conduit API介绍

On Relational operators in JS

Linux服务器装mysql数据库(详细教程)

Leetcode high frequency question: image intersection and union ratio IOU calculation method and hand tearing code

AcWing 396. 矿场搭建 题解(tarjan割点)

乐视成了反内卷之王:员工过上了没有996的神仙日子!

MySQL trigger

MySQL到底是如何执行SQL语句的

Duplicate disk: problems when BN and dropout are used together

RPA生态系统大揭秘,支撑RPA企业数十亿估值的生命本源
随机推荐
Istio灰度发布:部署Bookinfo微服务项目
信息收集
淺學js中的關系運算符
LETV has become the king of anti involution: employees have lived a fairy life without 996!
App packet capturing tips how to break network exceptions?
Introduction to phabricator conduct API
升级版打榜活动再次火热袭来,放眼望去全是奖金
[Huang ah code] getting started with MySQL - 2. Using data definition language (DDL) to operate the database
Copy the contents of one folder to another folder
正则表达式
Configuration actuelle de freeswitch
Introduction to phabricator conduct API
FreeSwitch的限流配置
Spatial attribute overview C language
机器学习笔记 - 基于Keras的GAN:图像去模糊的应用
【C】动态内存管理
What if win11 always pops up the input experience
How to make underline style of selected items
Cann experience officer's fifth experience documentary (Part 1)
Simple and efficient code suggestions