C PRIMER PLUS 第13章 第7题 b小题
作者:互联网
#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;
}
标签:input2,file2,13,NULL,temp,file1,PLUS,PRIMER,BUF 来源: https://blog.csdn.net/zyw602214944/article/details/118371326