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.pswp.cn/news/379540.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379540.shtml
英文地址,請注明出處:http://en.pswp.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…