您的位置:首页 > 其它

文件函数的小结(1)

2014-04-15 20:40 267 查看

文件的读写

一.字符读写函数( 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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: