当前位置:首页 » 编程语言 » 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-07-12 19:53:17 浏览:46
电脑中的微信聊天记录在哪里存储 发布:2025-07-12 19:47:22 浏览:944
苹果6sp怎么设置密码 发布:2025-07-12 19:28:50 浏览:547
电视下架缓存的还能看吗 发布:2025-07-12 19:14:12 浏览:444
安卓平板微软平板和苹果哪个好 发布:2025-07-12 19:09:37 浏览:413
数据库地区 发布:2025-07-12 19:05:41 浏览:395
如何检查vds脚本 发布:2025-07-12 19:04:24 浏览:908
命令行编译vs2013 发布:2025-07-12 19:01:22 浏览:808
c语言输出所有素数 发布:2025-07-12 19:01:19 浏览:659
查电费账号密码多少 发布:2025-07-12 18:56:19 浏览:545