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

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

输出量

fwrite example in c

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

fwrite函数的用法示例

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379540.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

标题:递增三元组

标题&#xff1a;递增三元组 给定三个整数数组 A [A1, A2, … AN], B [B1, B2, … BN], C [C1, C2, … CN]&#xff0c; 请你统计有多少个三元组(i, j, k) 满足&#xff1a; 1 < i, j, k < NAi < Bj < Ck 【输入格式】 第一行包含一个整数N。 第二行包含N个整…

伙伴算法、slab机制、内存管理函数

文章目录1 伙伴算法页框操作alloc_pages()2 slabslab机制要解决的问题使用高速缓存3 内存管理函数kmallockzallocvmallocvzalloc区别参考文章内核使用struct page结构体描述每个物理页&#xff0c;也叫页框。内核在很多情况下&#xff0c;需要申请连续的页框&#xff0c;而且数…

eval 函数 代替函数_eval()函数以及JavaScript中的示例

eval 函数 代替函数eval()函数 (eval() function) eval() function is a predefined global function in JavaScript and it is used to evaluate (execute) an expression, which is passed to the function as a parameter. It can also evaluate any JavaScript code. eval(…

F# ≥ C#(活动模式 和枚举)

F#提供了一个叫"活动模式"的有趣功能。它把输入的数据转换成其他不同的东西。 一个有趣的使用实例就是代替枚举。但我编程枚举的时候&#xff0c;我总不高兴去链接枚举项到它的定义。例如&#xff0c;下面的枚举定义了 数字枚举&#xff0c; enum Numbers{Odd,Even,}…

关于java的classpath设置

今天晚上实验室的另一个人在编译一个java程序&#xff0c;需要用到一个jar文件&#xff0c;所以在命令行编译的时候需要添加jar的路径&#xff0c;例如&#xff1a; java -classpath demo.jar hello 但是设置了path之后java就不会搜索当前目录&#xff0c;也就是所如果hello在当…

C语言uthash的用法

文章目录1 定义一个哈希表键值UT_hash_handle2 哈希操作声明添加查找删除获取哈希表中元素个数迭代排序3 案例键的使用官网解释&#xff1a;https://troydhanson.github.io/uthash/userguide.html 在使用之前&#xff0c;我们必须包含uthash.h的头文件&#xff0c;你需要将该头…

Javascript Paste Keyboard Shortcuts Hijack

author : kj021320 team : I.S.T.O 这样的攻击手段也算是极其无耻 猥琐之极! 所以防御措施一定要做好 首先说一下通过Javascript Paste Keyboard Shortcuts Hijack能做什么???能够读取你本地机器任何文件! 没错!也就是说 你中了任何一个XSS 加上你按了粘贴快捷键后,你就有可…

python 生成器表达式_Python中的列表理解与生成器表达式

python 生成器表达式The list is a collection of different types of elements and there are many ways of creating a list in Python. 该列表是不同类型元素的集合&#xff0c;并且有许多方法可以在Python中创建列表。 清单理解 (List Comprehension) List comprehension…

Javaweb---监听器

1.什么是监听器 监听器就是监听某个对象的状态变化的组件。 事件源&#xff1a;被监听的对象 ----- 三个域对象 request session servletContext 监听器&#xff1a;监听事件源对象 事件源对象的状态的变化都会触发监听器 ---- 62 注册监听器&#xff1a;将监听器与事件源进行…

Linux中的Ramdisk和Initrd

Ramdisk简介先简单介绍一下ramdisk&#xff0c;Ramdisk是虚拟于RAM中的盘(Disk)。对于用户来说&#xff0c;能把RAM disk和通常的硬盘分区&#xff08;如/dev/hda1&#xff09;同等对待来使用&#xff0c;例如&#xff1a;redice # mkfs.ext2 /dev/ram0mke2fs 1.38 (30-Jun-200…

slab下kmalloc内核函数实现

文章目录kmalloc的整体实现获取高速缓存高速缓存获取index总结https://blog.csdn.net/qq_41683305/article/details/124554490&#xff0c;在这篇文章中&#xff0c;我们介绍了伙伴算法、slab机制和常见的内存管理函数&#xff0c;接下来&#xff0c;我们看看kmalloc内核函数的…

PHP array_merge_recursive()函数与示例

PHP array_merge_recursive()函数 (PHP array_merge_recursive() function) array_merge_recursive() function is used to merge two or more arrays, it returns a new array with merged elements. The only difference between array_merge() and array_merge_recursive() …

标题:三羊献瑞

标题&#xff1a;观察下面的加法算式&#xff1a; 其中&#xff0c;相同的汉字代表相同的数字&#xff0c;不同的汉字代表不同的数字。 请你填写“三羊献瑞”所代表的4位数字&#xff08;答案唯一&#xff09;&#xff0c;不要填写任何多余内容。 思路分析&#xff1a; 首先…

hdu 1069

地址&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1069 题意&#xff1a;给定若干个木块长宽高&#xff0c;长宽高可以自己调整&#xff0c;求堆积起来最高的高度。 mark&#xff1a;枚举所有木块长宽高可能情况&#xff0c;简单dp。 代码&#xff1a; #include <…

简明 Python 编程规范

简明 Python 编程规范编码 所有的 Python 脚本文件都应在文件头标上 # -*- coding:utf-8 -*- 。设置编辑器&#xff0c;默认保存为 utf-8 格式。注释 业界普遍认同 Python 的注释分为两种的概念&#xff0c;一种是由 # 开头的“真正的”注释&#xff0c;另一种是 docstri…

进程虚拟地址管理

文章目录1 地址分布实际使用中的内存区域2 进程的虚拟地址描述用户空间mmap线程之间共享内存地址的实现机制1 地址分布 现在采用虚拟内存的操作系统通常都使用平坦地址空间&#xff0c;平坦地址空间是指地址空间范围是一个独立的连续空间&#xff08;比如&#xff0c;地址从0扩…

java两个文件夹比较路径_比较Java中两个文件的路径

java两个文件夹比较路径Given the paths of the two files and we have two compare the paths of the files in Java. 给定两个文件的路径&#xff0c;我们有两个比较Java中文件的路径。 Comparing paths of two files 比较两个文件的路径 To compare the paths of two file…

标题:加法变乘法

标题&#xff1a;我们都知道&#xff1a;123 … 49 1225 现在要求你把其中两个不相邻的加号变成乘号&#xff0c;使得结果为2015 比如&#xff1a; 123…10*1112…27*2829…49 2015 就是符合要求的答案。 请你寻找另外一个可能的答案&#xff0c;并把位置靠前的那个乘号左…

C# winform对话框用法大全收藏

对话框中我们常用了以下几种&#xff1a; 1、文件对话框(FileDialog) 它又常用到两个&#xff1a; 打开文件对话框(OpenFileDialog) 保存文件对话(SaveFileDialog) 2、字体对话框(FontDialog) 3、颜色对话框(&#xff23;olorDialog) 4、打印预浏对话框(PrintPreviewDialog) 5、…

【翻译】eXpressAppFramework QuickStart 业务模型设计(四)—— 实现自定义业务类...

这一讲&#xff0c;你将学到如何从头开始实现业务类。为此&#xff0c;将要实现Department和Position业务类。这些类将被应用到之前实现的Contact类中。你将学到引用对象自动生成用户界面的基本要素。 在此之前&#xff0c;我建议你去阅读一下 【翻译】eXpressAppFramework Qui…