當前位置:首頁 » 編程語言 » fread函數c語言

fread函數c語言

發布時間: 2025-02-19 22:14:29

Ⅰ 關於C語言fread的用法

簡介
fread


能:
從一個流中讀數據

函數原型:
size_t
fread(
void
*buffer,
size_t
size,
size_t
count,
file
*stream
);


數:

1.用於接收數據的地址(指針)(buffer)

2.單個元素的大小(size)
:單位是位元組而不是位,例如讀取一個整型數就是2個位元組

3.元素個數(count)

4.提供數據的文件指針(stream)

返回值:成功讀取的元素個數
程序例
#include

int
main(void)

{

file
*stream;

char
msg[]
=
"this
is
a
test";

char
buf[20];

if
((stream
=
fopen("mmy.fil",
"w+"))
==
null)

{

fprintf(stderr,
"cannot
open
output
file.\n");

return
1;

}
/*
write
some
data
to
the
file
*/

fwrite(msg,
strlen(msg)+1,
1,
stream);
/*
seek
to
the
beginning
of
the
file
*/

fseek(stream,
0,
seek_set);
/*
read
the
data
and
display
it
*/

fread(buf,
strlen(msg)+1,
1,stream);

printf("%s\n",
buf);

fclose(stream);

return
0;

}

熱點內容
易語言源碼怎麼保存 發布:2025-04-23 01:36:28 瀏覽:159
查看應用數據的存儲路徑 發布:2025-04-23 01:36:18 瀏覽:382
winformaccess資料庫 發布:2025-04-23 01:31:20 瀏覽:166
免費申請騰訊雲伺服器 發布:2025-04-23 01:23:12 瀏覽:731
阿里雲上傳慢 發布:2025-04-23 01:04:10 瀏覽:586
我爸電腦配置給別人看沒什麼事吧 發布:2025-04-23 00:58:54 瀏覽:723
大學編程課程 發布:2025-04-23 00:48:55 瀏覽:470
伺服器的內網ip有什麼用 發布:2025-04-23 00:46:40 瀏覽:958
誅仙3需要什麼配置 發布:2025-04-23 00:29:49 瀏覽:665
什麼是編譯錯誤參數不可選 發布:2025-04-23 00:23:06 瀏覽:520