实例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;
}
时间: 2024-12-29 07:21:16