实例2:读取字符文件,每次读入一个缓存里面。
#include<stdio.h>
#include <stdlib.h>
#define MAXLEN 1024
int main()
{
FILE *fin;
FILE *fout=fopen("c:\\dest.txt","wt");
char buf[MAXLEN];
if((fin=fopen("c:\\test.txt","rt"))!=NULL)
{
char* c =fgets(buf,MAXLEN,fin);
while(c!=0)
{
fputs(buf,fout);
c =fgets(buf,MAXLEN,fin);
}
}
else
{
printf("file not exist!");
exit(1);
}
fclose(fin);
fclose(fout);
return 0;
}
原文:http://simoniu.blog.51cto.com/2566344/1409138