文件编程

来源:百度知道 编辑:UC知道 时间:2024/06/04 07:15:29
已知文本文件File1,试编程序对文件File中的每个字符连续显示两次。

比较简单,一个完整的c程序如下,在win-tc和Dev-c++下已运行通过。
#include<stdio.h>

int main(void)
{
FILE *fp;
char ch;
if((fp=fopen("file1.txt","r"))==NULL)
{
printf("Cannot open file1.txt. Strike any key to exit!");
system("pause");
exit(1);
}
ch=fgetc(fp);
while(!feof(fp))
{
putchar(ch);
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
printf("\n\n");
system("pause");
return 0;
}