文件函数的小结(1)

文件的读写

一.字符读写函数( fgetc, fputc )

读:字符变量= fgetc( 文件指针);

写:写入字符或EOF = fputc(字符量, 文件指针);


二.字符串读写函数(fgets, fputs)

字符串地址 = fgets(字符数组名,  n, 文件指针);

非负整数= fputs(字符串, 文件指针);


三.数据块读写函数(fread,fwrite)

实际读取的元素个数=fread(butter, size, count, fp);

实际写入的元素个数= fwrite(butter, size, count, fp);

(1)buffer:是一个指针,对fread来说,它是读入数据的存放地址。对fwrite来说,是要输出数据的地址。

(2)size:要读写的字节数;

(3)count: 要进行读写多少个size字节的数据项;

(4)fp:文件型指针。

size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );

	Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr.

	The position indicator of the stream is advanced by the total amount of bytes read.The total amount of bytes read if successful is (size*count).size_t is an unsigned integral type.


四.格式化读写函数(fscanf,fprintf)

成功读入的参数的个数= fscanf ( fp , "%s %d %lf" , a , &b , &c);

返回输出字符数= fprintf(fp, “%d %c”, j, ch);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值