
C语言“fread”函数的用法?
C语言“fread”函数的用法为“size_tf read(void *buffer,size_t size,size_t count,FILE *stream)”,其作用是从一个文件流中读数据,读取count个元素,每个元素size字节。
示例1
#include <stdio.h>
#include <process.h>
#include <string.h>
int main()
{
FILE *stream;
char msg[]="this is a test";
char buf[20];
if ((stream=fopen("dummy.fil","w+"))==NULL)
{
fprintf(stderr,"cannot open output file.\n");
return 1;
}
/*write some data to the file*/
fwrite(msg,1,strlen(msg)+1,stream);
/*seek to the beginning of the file*/
fseek(stream,0,SEEK_SET);
/*read the data and display it*/
fread(buf,1,strlen(msg)+1,stream);
printf("%s\n",buf);
fclose(stream);
system("pause");
return 0;
}示例2
采用 php+mysql 数据库方式运行的强大网上商店系统,执行效率高速度快,支持多语言,模板和代码分离,轻松创建属于自己的个性化用户界面 v3.5更新: 1).进一步静态化了活动商品. 2).提供了一些重要UFT-8转换文件 3).修复了除了网银在线支付其它支付显示错误的问题. 4).修改了LOGO广告管理,增加LOGO链接后主页LOGO路径错误的问题 5).修改了公告无法发布的问题,可能是打压
0
立即学习“C语言免费学习笔记(深入)”;
int main(void)
{
FILE *stream;
char list[30];
int i,numread,numwritten;
/*open file in text mode:*/
if ((stream=fopen("fread.out","w+t"))!=NULL)
{
for (i=0;i<25;i++)
{
list[i]=(char)('z'-i);
}
/*write 25 characters to stram*/
numwritten=fwrite(list,sizeof(char),25,stream);
printf("Wrote %d items\n",numwritten);
fclose(stream);
}
else
printf("Problem opening the file\n");
if ((stream=fopen("fread.out","r+t"))!=NULL)
{
numread=fread(list,sizeof(char),25,stream);
printf("Number of items read =%d\n",numread);
printf("Contents of buffer=%.25s\n",list);
fclose(stream);
}
else
{
printf("File could not be opened\n");
}
system("pause");
return 0;
}推荐教程:《PHP》
以上就是C语言“fread”函数的用法?的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号