int main()
{
FILE *fp1;
FILE *fp2;
FILE *fp3;
char ch1;
char ch2;
char ch3;
if((fp1 = fopen("text1.txt","r")) == NULL)
{
printf("file is error!\n");
exit(0);
}
if((fp2 = fopen("text2.txt","r")) == NULL)
{
printf("file is error!\n");
exit(0);
}
if((fp3 = fopen("text3.txt","w+")) == NULL)
{
printf("file is error!\n");
exit(0);
}
while(((ch1 = fgetc(fp1)) != EOF) && ((ch2 = fgetc(fp2)) != EOF))
{
if((ch1 >= '0') && (ch1 <= '9'))
{
if((ch2 >= '0') && (ch2 <= '9'))
{
ch3 = (ch1 - '0') + (ch2 - '0') + '0';
fputc(ch3,fp3);
}
}
else
{
fputc(ch1,fp3);
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
return 0;
}
有关文件的小练习题
最新推荐文章于 2021-11-21 16:41:55 发布