c语言文件初步入门文本拷贝
可判断文件是否打开
创建文件inflie.c
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *infp,*outfp;
char ch;
if((infp=fopen("infile.c","r"))==NULL)
{
printf("cannot open infile.c.\n");
exit(0);
}
if((outfp=fopen("outfile.c","w"))==NULL)
{
printf("cannot open outfile.c.\n");
exit(0);
}
#if 0
#else
while(1){
ch=fgetc(infp);
if(ch==EOF)
break;
fputc(ch,outfp);
}
#endif
fclose(infp);
fclose(outfp);
}
进行复制infile.c的内容进入outfile.c中