#include<stdio.h>
#include<string.h>
void main(int argc , char * argv[])
{
FILE *file1,*file2;
char line1[100],line2[100];
file1 = fopen(argv[1],"r");
file2 = fopen(argv[2],"r");
while(1)
{
if(fscanf(file1,"%[^\n]\n",line1)!=EOF && fscanf(file2,"%[^\n]\n",line2)!=EOF)
{
if(strcmp(line1,line2) == 0)
printf("\t\t | \t\t | %s\n",line1);
else
printf("%s | %s | \n",line1,line2);
}
else if(fscanf(file1,"%[^\n]\n",line1)!=EOF)
printf("%s | \t\t |\n",line1);
else if(fscanf(file2,"%[^\n]\n",line2)!=EOF)
printf("\t\t | %s | \n",line2);
else
break;
}
fclose(file1);
fclose(file2);
}
OUTPUT:
cc comm.c
./a.out file1.txt file2.txt
#include<string.h>
void main(int argc , char * argv[])
{
FILE *file1,*file2;
char line1[100],line2[100];
file1 = fopen(argv[1],"r");
file2 = fopen(argv[2],"r");
while(1)
{
if(fscanf(file1,"%[^\n]\n",line1)!=EOF && fscanf(file2,"%[^\n]\n",line2)!=EOF)
{
if(strcmp(line1,line2) == 0)
printf("\t\t | \t\t | %s\n",line1);
else
printf("%s | %s | \n",line1,line2);
}
else if(fscanf(file1,"%[^\n]\n",line1)!=EOF)
printf("%s | \t\t |\n",line1);
else if(fscanf(file2,"%[^\n]\n",line2)!=EOF)
printf("\t\t | %s | \n",line2);
else
break;
}
fclose(file1);
fclose(file2);
}
OUTPUT:
cc comm.c
./a.out file1.txt file2.txt
Comments
Post a Comment