C语言fread函数_C语言fread
大家好,又见面了,我是你们的朋友全栈君。
c语言中fread函数
C语言中的fread()函数 (fread() function in C)
Prototype:
原型:
size_t fread(void *buffer, size_t length, size_t count, FILE *filename);
Parameters:
参数:
void *buffer, size_t length, size_t count, FILE *filename
Return type: size_t
返回类型: size_t
Use of function:
使用功能:
The prototype of the function fread() is:
函数fread()的原型为:
size_t fread(void *buffer, size_t length, size_t count, FILE *filename);
In the file handling, through the fread() function, we read the count number of objects of size length from the input stream filename to the array named buffer. Its returns the number of objects being read from the file. If lesser no of objects are read or EOF is encountered before then it will give an error.
在文件处理中,通过fread()函数 ,我们从输入流文件名到名为buffer的数组读取大小为长度的对象的计数 。 它返回从文件中读取的对象数。 如果较少的对象没有被读取或在此之前遇到EOF ,则它将给出错误。
C语言中的fread()示例 (fread() example in C)
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *f;
//initialize the arr1 with values
int arr1[5]={
1,2,3,4,5};
int arr2[5];
int i=0;
//open the file for write operation
if((f=fopen("includehelp.txt","w"))==NULL){
//if the file does not exist print the string
printf("Cannot open the file...");
exit(1);
}
//write the values on the file
if((fwrite(arr1,sizeof(int),5,f))!=5){
printf("File write error....\n");
}
//close the file
fclose(f);
//open the file for read operation
if((f=fopen("includehelp.txt","r"))==NULL){
//if the file does not exist print the string
printf("Cannot open the file...");
exit(1);
}
//read the values from the file and store it into the array
if((fread(arr2,sizeof(int),5,f))!=5){
printf("File write error....\n");
}
fclose(f);
printf("The array content is-\n");
for(i=0;i<5;i++){
printf("%d\n",arr2[i]);
}
return 0;
}
Output
输出量
翻译自: https://www.includehelp.com/c-programs/fread-function-in-c-language-with-example.aspx
c语言中fread函数
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/194507.html原文链接:https://javaforall.cn
相关文章
- C语言qsort函数用法
- C语言中的strstr函数的用法「建议收藏」
- C语言字符串输入及输出的几种方式
- C语言“fread”函数的用法?「建议收藏」
- C语言-函数-递归数列
- 小白学习C语言 第3天
- Linux下C语言编译器安装指南(linuxc编译器安装)
- 指针与数组的关系,C语言指针和数组的关系详解
- gets函数,C语言gets函数详解
- fgets函数及其用法,C语言fgets函数详解
- C语言函数声明
- 字符串查找函数,C语言字符串查找函数详解
- puts和fputs函数及其区别,C语言puts和fputs函数详解
- feof和ferror函数,C语言feof和ferror函数详解
- C语言fmod()函数:求x/y的余数(针对浮点数)
- C语言div()函数:求两个数的商和余数
- C语言abs()函数:求整数的绝对值
- C语言isgraph()函数:判断一个字符是否是图形字符
- C语言isprint()函数:判断一个字符是否是可打印字符
- listLinux C语言链表编程实战(linuxclink)
- Linux与C语言编程必备书籍(linuxc书)
- 学习Linux、C语言与PDF阅读的技巧(linuxcpdf)
- Linux下C语言开发环境搭建简易教程(linuxcide)
- Linux C语言界面开发:新时代的编程之旅(linux c 界面开发)
- 搭建C语言MySQL环境,调试Web程序必备(c mysql 环境)
- 处理MySQL批量处理技术C语言助你加速升级(c mysql 批量)
- 代码管理MySQLC语言快速操纵MySQL,一行代码搞定(c mysql一行)
- 如何正确配置C语言Oracle数据库库文件(c oracle 库文件)
- 浅析C语言中sscanf的用法
- C语言typedef与复杂函数声明问题的深入解析
- 利用C语言实现HashTable
- C语言安全编码数组记法的一致性
- C语言new操作的安全性分析
- Lua教程(四):在Lua中调用C语言、C++的函数