#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define BUF 256
int main(void)
{
char file1[BUF];
char file2[BUF];
FILE *input1,*input2;
char temp[BUF];
printf("输入要打开的两个文件的文件名,以空格隔开\n");
while ((scanf("%s%s", file1, file2)) != 2)
printf("文件名错误,请重试\n");
if ((input1 = fopen(file1, "r")) == NULL)
{
printf("打开文件%s失败",file1);
exit(EXIT_FAILURE);
}
if ((input2 = fopen(file2, "r")) == NULL)
{
printf("打开文件%s失败",file2);
exit(EXIT_FAILURE);
}
while ((fgets(temp, BUF, input1)) != NULL)
{
char* find;
if (find = strchr(temp, '\n'))
*find = '\0';
fputs(temp, stdout);
if ((fgets(temp, BUF, input2)) != NULL)
fputs(temp, stdout);
}
while ((fgets(temp, BUF, input2)) != NULL)
fputs(temp, stdout);
fclose(input1);
fclose(input2);
return 0;
}