当前位置:首页 » 编程语言 » 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-09-16 13:28:58 浏览:337
连接ftp异常中断 发布:2025-09-16 12:52:33 浏览:287
3m移动办公服务器地址大全 发布:2025-09-16 12:22:35 浏览:256
什么是直男的快乐密码 发布:2025-09-16 12:22:32 浏览:910
修改数据库存储引擎 发布:2025-09-16 12:21:48 浏览:77
安徽调度服务器品牌云服务器 发布:2025-09-16 12:02:17 浏览:777
数据库表设计教程 发布:2025-09-16 10:50:47 浏览:348
朋友圈缓存如何清除 发布:2025-09-16 10:49:57 浏览:446
sqlserver数据类型 发布:2025-09-16 10:41:16 浏览:740
如何配置全站时间同步系统 发布:2025-09-16 10:19:13 浏览:177