首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

帮忙看一下这段文件读取的代码解决思路

2012-04-26 
帮忙看一下这段文件读取的代码#includestdio.h#include sys/stat.hmain(){ ?struct stat buf ?char a

帮忙看一下这段文件读取的代码
#include<stdio.h>
#include <sys/stat.h>

main()
{
? struct stat buf;
? char a[12323];
? char c;
? char name[20];
? printf("Do you want to read a file?\n");
? c=getchar();
? if(c=='y'||c=='Y'){
printf("please enter the file name you want to read: ");
scanf("%s",name);
? freopen(name,"r",stdin);
? while(scanf("%s",a)!=EOF){
? printf(" %s ",a);
? }
? if(stat(name,&buf)==0){
? printf("%d",buf.st_atime);
? }
? printf("the file %s has been readed",name);
? freopen(name,"r",stdin);
? freopen("fd.doc","w+",stdout);
? while(scanf("%s",a)!=EOF){
? printf(" %s ",a);
? }
? }
}
虽然能读取纯文本文件,但是读其他文件时读不了,因为其它文件包含文件头,其中包括它的格式之类的信息,我想全都读进来,该怎么办?

[解决办法]
用二进制模式打开
[解决办法]
奇怪,你换2进制模式试下吧。
我试过直接读的时候,可以读出文件头的。

热点排行