当前位置:网站首页>LIinux下的基本C编程的三类高频函数操作详解第一类——文件操作函数(f)
LIinux下的基本C编程的三类高频函数操作详解第一类——文件操作函数(f)
2022-07-22 18:11:00 【张铁牛(IOT)】
文件操作函数
fput和fputs
fputc函数用于把一个字符(字符常量/字符变量)写入磁盘文件
一般形式:
ch=fputs(ch,fp);其中ch是要写入的字符,fp是文件指针变量,写入成功返回写入的字符,写入失败返回EOF;
fputs和其相似,向指定文件写入字符串(字符串常量,字符串组名,变量)
一般形式:
fputs(字符串,文件指针);fgetc和fgets
fgetc函数用于从指定文件中读取字符赋予ch
一般形式:
ch=fgetc(fp);
文件必须以读或读写的方式打开,当函数遇到结束文件符时,将返回文件结束标志EOF;
fgets与其相似,用于指定的文件中读取一个字符串到字符数组中
一般形式:
fgets(字符数组名,n,文件指针);//n表示字符串的个数。fprintf(写入)和fscanf(读取)
fprintf函数一般类型:
ch=fprintf(文件类型指针,格式字符串,输入列表);
fscanf函数一般类型:
fscanf(文件类型指针,格式字符串,输出列表);fread和fwrite
fread是从fp指向的文件中读取count次,每次读取size字节,读取的信息保存在buffer地址中
一般形式:
fread(buffer,size,count,fp);
fwrite是将buffer地址开始的信息输出count次,每次写size字节到fp指向的文件中
一般形式:
fwrite(buffer,size,count,fp);fseek
fseek函数用于移动文件内部的位置指针
一般形式:
fseek(文件指针类型,位移量,起始点);rewind
rewind函数用于将位置指针重返文件开头,没有返回值
一般形式:
int rewind(文件类型指针);ftell
ftell函数可得到流式文件中的当前位置,并使用相对于文件头的位移量表示
一般形式:
long ftell(文件类型指针);边栏推荐
- vector与迭代器部分内容学习
- KMP
- PTP Beidou time server (satellite clock server) helps the college entrance examination information system
- Software life cycle model ----- V model
- Test preface 2
- Software testing is divided by stages: unit testing, integration testing, system testing, acceptance testing
- Optional一致性
- echo音箱配对及操作方法
- Fundamentals of software testing
- Iptables firewall
猜你喜欢
随机推荐
amber教程4.6:对体系氢键分析
Basic process of unit approval
Regular expression II
Software testing process
存储过程
Software testing ~ learning / advanced route
关于使用VMD的对齐功能
Iptables firewall
Amber tutorial 3.2: GPU viewing and running MD with pmemd engine
Learn the input file parameters of amber software MD
Strategies of test case design and writing
Day 3 summary & homework
Learning about background mount and process management
Shallow shaking automatic test
Learn the MD of amber t3.3: implicit solvent model (GB)
Optional一致性
读《高效阅读法-最划算的自我投资》有感
正则表达式Ⅱ
Software test classification
Common test case methods




![[original] software test example guidance](/img/74/4d1e6cd537d4948dace95633140939.png)




