题目:手动创建两个文本文件text1.txt,text2.txt,要求编程创建text3.txt,实现text1.txt和text2.txt文件中除去首行和末尾对应的数据相加,三个文本的内容如上
程序如下:#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1,*fp2,*fp3;
char ch1,ch2,ch3;
if((fp1 = fopen("1.txt","r+")) == NULL)
{
printf("open error!\n");
exit(-1);
}
if((fp2 = fopen("2.txt","r+")) == NULL)
{
printf("open error!\n");
exit(-1);
}
if((fp3 = fopen("3.txt","w")) == NULL)
{
printf("open error!\n");
exit(-1);
}
while((ch1 = fgetc(fp1)) != EOF)
{
ch2 = fgetc(fp2);
if(isdigit(ch1))
{
fputc(ch2 + ch1 - '0',fp3);
}
else
{
fputc(ch1,fp3);
}
}
return 0;
}