c语言:如何将文件输出至屏幕
如何将原D:\\f1.txt文件输出至屏幕#include<stdio.h>#include<stdlib.h>intmain(){FILE*fp,*fin;charch...
如何将原D:\\f1.txt文件输出至屏幕
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp,*fin;
char ch;
fp=fopen("D:\\f1.txt","r");
if(!fp)
{
printf("can't open file\n");
exit(1);
}
fin=fopen("D:\\f2.txt","w");
if(!fin)
{
printf("can't open file\n");
exit(1);
}
while ((ch=fgetc(fp))!=EOF)
{
if ( (ch >='a' && ch <='z') || (ch >='A' && ch <='Z') )
{
fprintf(fin, "%c %d\n", ch, ch );
}
}
fclose(fp);
fclose(fin);
return 0;
} 展开
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp,*fin;
char ch;
fp=fopen("D:\\f1.txt","r");
if(!fp)
{
printf("can't open file\n");
exit(1);
}
fin=fopen("D:\\f2.txt","w");
if(!fin)
{
printf("can't open file\n");
exit(1);
}
while ((ch=fgetc(fp))!=EOF)
{
if ( (ch >='a' && ch <='z') || (ch >='A' && ch <='Z') )
{
fprintf(fin, "%c %d\n", ch, ch );
}
}
fclose(fp);
fclose(fin);
return 0;
} 展开
展开全部
以下程序能将文件原文输出到屏幕:
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("D:\\f1.txt","r");
if(!fp)
{
printf("can't open file\n");
exit(1);
}
while ((ch=fgetc(fp))!=EOF)
printf("%c", ch);
fclose(fp);
return 0;
}
追问
可是这样的话就不能复制到f2文件上了呢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询