#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<process.h>
int main(int argc,char *argv[])
{
FILE *fp1;
FILE *fp2;
char ch1;
char ch2;
int i=1;
int j=1;
if((fp1=fopen(argv[1],"r"))==NULL)
{
printf("Can't open file %s.\n",argv[1]);
exit(EXIT_FAILURE);
}
if((fp2=fopen(argv[2],"r"))==NULL)
{
printf("Can't open file %s.\n",argv[2]);
exit(EXIT_FAILURE);
}
ch1=getc(fp1);
ch2=getc(fp2);
while((ch1!=EOF)||(ch2!=EOF))
{
while((ch1!=EOF)&&(ch1!='\n'))
{
putc(ch1,stdout);
ch1=getc(fp1);
}
if(ch1!=EOF)
{
putchar('\n');
ch1=getc(fp1);
}
if((ch1==EOF)&&(i==1)&&(j==1))//juge which file is first to get to the end.The fist one shule put a '\n' in the end and the other one need not to
{
putchar('\n');
i++;
j++;
}
while((ch2!=EOF)&&(ch2!='\n'))
{
putc(ch2,stdout);
ch2=getc(fp2);
}
if(ch2!=EOF)
{
putchar('\n');
ch2=getc(fp2);
}
if((ch1==EOF)&&(j==1)&&(i==1))//juge which file is first to get to the end.The fist one shule put a '\n' in the end and the other one need not to
{
putchar('\n');
j++;
i++;
}
}
if(fclose(fp1)!=0)
printf("Can't close the file %s\n",argv[1]);
if(fclose(fp2)!=0)
printf("Can't close the file %s\n",argv[2]);
exit(EXIT_SUCCESS);
system("pause");
return 0;
}