fwrite函数的用法示例

C中的fwrite()函数 (fwrite() function in C)

Prototype:

原型:

    size_t fwrite(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 fwrite() is:

函数fwrite()的原型为:

    size_t fwrite(void *buffer, size_t length, size_t count, FILE *filename);

In the file handling, through the fwrite() function we write count number of objects of size length to the input stream filename from the array named as buffer. Its returns the number of objects that it will write to the file. If fewer number of objects will be written or EOF is encountered then it will throw an error.

在文件处理中,通过fwrite()函数,我们将大小为长度的对象的计数写入名为缓冲区的数组的输入流文件名中。 它返回将写入文件的对象数。 如果要写入的对象数量较少或遇到EOF ,则它将引发错误。

C语言中的fwrite()示例 (fwrite() 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);
for(i=0;i<5;i++){printf("%d\n",arr2[i]);
}
return 0;
}

Output

输出量

翻译自: https://www.includehelp.com/c-programs/fwrite-function-in-c-language-with-example.aspx

fwrite函数的用法示例

fwrite函数的用法示例_C语言中的fwrite()函数(带有示例)相关推荐

  1. 单片机sleep函数的头文件_C语言中的sleep() 函数

    展开全部 关于sleep()函数在windows系统和linux系统下是两个不同的函数,差别较大,但功能是相同的,都是将进程挂起e68a8462616964757a686964616f31333337 ...

  2. C语言 SLEEP函数不起作用,C语言中的sleep() 函数 sleep函数的具体用法

    导航:网站首页 > C语言中的sleep() 函数 sleep函数的具体用法 C语言中的sleep() 函数 sleep函数的具体用法 相关问题: 匿名网友: 关于sleep()函数在windo ...

  3. c语言fputc 函数头,简单对比C语言中的fputs()函数和fputc()函数

    简单对比C语言中的fputs()函数和fputc()函数 C语言fputc()函数:写文件函数(将一指定字符写入文件流中) 头文件: #include 定义函数: int fputc(int c, F ...

  4. c cin.get()的用法小结_c语言中static 用法

    static在c里面可以用来修饰变量,也可以用来修饰函数. 先看用来修饰变量的时候.变量在c里面可分为存在全局数据区.栈和堆里.其实我们平时所说的堆栈是栈而不是堆,不要弄混. int a ; int ...

  5. c语言中exit函数可以返回嘛,C语言中的exit函数 以及他与return函数的区别

    1.   exit() 结束当前进程/当前程序/,在整个程序中,只要调用 exit ,就结束 exit(0)表示进程正常退出. 返回 0; exit(1)表示进程非正常退出. 返回 1. 2.    ...

  6. merge函数_c语言中的merge函数

    展开全部 merge()是C++标准库的函数,主要实现函数的排序和合并,不仅仅是合并,具体要求参e5a48de588b63231313335323631343130323136353331333431 ...

  7. c语言strcpy函数的示例,c语言中的strcpy函数讨论

    strcpy函数的原型是 char *strcpy(char *strDest, const char *strScr) { char *address=strDest; assert((strDes ...

  8. linux c语言sleep函数的头文件,C语言中的pause()函数和alarm()函数以及sleep()函数

    C语言pause()函数:让进程暂停直到信号出现头文件: #include 定义函数: int pause(void); 函数说明:pause()会令目前的进程暂停(进入睡眠状态), 直到被信号(si ...

  9. putc函数_C语言中的putc()函数与示例

    putc函数 C语言中的putc()函数 (putc() function in C) The putc() function is defined in the <stdio.h> he ...

最新文章

  1. jQuery原理系列-css选择器实现
  2. xmldocument如何创建一个不带结尾的节点_LDF文件是个啥?如何创建一个LDF文件
  3. nyist --- 组队赛(四)
  4. 回车无法直接提交当前光标所在控件中的数据
  5. 导致大量kworker的原因_高尿酸与生活习惯有关?导致高尿酸的8个坏习惯,现在改还来得及...
  6. LeetCode 755. 倒水(模拟)
  7. linux重新安装xrog文件,Linux下重新生成xorg.conf
  8. 吉林农业科技学院计算机大师,吉林农业科技学院
  9. 项目管理工具project软件学习(六) - 设置里程碑、任务备注
  10. xampp配置时几个重要的目录
  11. 开课吧:深入了解C++语言应用方向有哪些?
  12. Andorid AlertDialog 点击后自动消失_为何孙悟空成佛后,金箍儿就会自动消失?金箍儿究竟代表什么...
  13. 管理感悟:如何提交问题的解决方案
  14. python是一门胶水语言_python为何被称之为胶水语言
  15. Illumination Normalization Based on Weber’s Law With Application to Face Recognition
  16. 前端面试题整理 (ES6篇)
  17. java调用excel在页面生成饼状图_Java 在 Excel 中创建饼图/环形图
  18. 重复一下:关于Flash停止支持后Chrome如何启用过期插件
  19. FilterConfig接口及其使用方法详解
  20. 以前的java单机游戏过关长剑,玩过这些经典单机游戏_就说明你已经老了

热门文章

  1. 企业使用多大的光纤宽带合适呢-光纤接入
  2. RemObjects Remoting SDK for Delphi
  3. RemObjects Data Abstract数据库软件的最佳框架
  4. unity3d导出html,白鹭开发者中心
  5. 请问app项目怎么和后台一起部署到服务器,vue接通后端api以及部署到服务器操作...
  6. SuspendThread、ResumeThread(二)
  7. Tribon自定义图纸类型-删除图纸
  8. 有登陆认证的情况下如何使用Wisdom RESTClient?
  9. 将对象拷贝一份备用,改变原对象的属性时,为啥备份数据也改变了?(赋值、浅拷贝和深拷贝的区别)
  10. jin tian xin qing gen tian qi yi yang!