c语言fread函数的总结
2017-08-21 18:33
281 查看
头文件:#include <stdio.h>
函数原型:size_t fread(void *buffer, size_t size, size_t count, FILE *stream);
参数:
buffer:用于接收数据的内存地址;
size:表示要读的每个数据项的字节数,单位是字节;
count:要读count个数据项,每个数据项size个字节;
stream:输入流。
返回值:
如果调用成功返回实际读取到的项个数;
如果失败或读取到文件尾,返回0。
程序实例:
函数原型:size_t fread(void *buffer, size_t size, size_t count, FILE *stream);
参数:
buffer:用于接收数据的内存地址;
size:表示要读的每个数据项的字节数,单位是字节;
count:要读count个数据项,每个数据项size个字节;
stream:输入流。
返回值:
如果调用成功返回实际读取到的项个数;
如果失败或读取到文件尾,返回0。
程序实例:
#include<stdio.h> #include<string.h> int main(void) { FILE*stream; char msg[]="this is a test"; char buf[20]; if((stream=fopen("DUMMY.FIL","w+"))==NULL) { fprintf(stderr,"Can not open output file.\n"); return 0; } /*write some data to the file*/ fwrite(msg,1,strlen(msg)+1,stream); /*sizeof(char)=1 seek to the beginning of the file*/ fseek(stream,0,SEEK_SET); /*read the data and display it*/ fread(buf,1,strlen(msg)+1,stream); printf("%s\n",buf); fclose(stream); return 0; }
相关文章推荐
- C语言fread()函数
- c语言swap函数总结
- C语言输入输出函数总结
- C语言 fread()与fwrite()函数说明与示例
- C语言assert()函数用法总结
- c语言指针与函数形参和实参易错点总结
- UNIX下函数fgets和fputs、fread和fwrite、fscanf和fprintf用法总结
- C语言中获取和改变目录的相关函数总结
- c语言 inline函数的总结
- C++ 标准输入输出 函数 fopen fread等系列函数使用总结
- C语言文件操作函数总结
- C语言字符串函数总结
- C语言文件操作函数大全(看到总结的真的很好,就转载贡献给大家了)
- C语言assert()函数用法总结
- c语言中字符搜索函数的简单总结
- C语言中将字符串转化为数字的函数总结
- C语言内存分配函数总结
- C语言编程中从密码文件获取数据的函数总结
- 让你提前认识软件开发(18):C语言中常用的文件操作函数总结及使用方法演示代码
- 总结文件操作函数(一)-C语言