当前位置:首页 » 编程语言 » 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;

}

热点内容
php设置编码格式 发布:2025-09-16 15:20:04 浏览:608
php取两位小数点 发布:2025-09-16 15:12:40 浏览:311
加密块流加密 发布:2025-09-16 15:07:36 浏览:696
sqldeveloper导出表 发布:2025-09-16 15:07:33 浏览:362
xbox360ftp 发布:2025-09-16 14:45:34 浏览:847
火车站附近wifi密码是多少 发布:2025-09-16 14:45:30 浏览:190
国家标准加密 发布:2025-09-16 14:45:27 浏览:949
php集成支付宝 发布:2025-09-16 14:05:28 浏览:718
php的pregmatchall 发布:2025-09-16 14:04:43 浏览:437
片上缓存区 发布:2025-09-16 13:49:18 浏览:153