I need to compare two files and create a new one with the differences of this two, i just know compare the files to show if they are equal or not, but i dont know how can i solve my problem.
I search so much info on how to compare files, but i didnt found the way of display the differences between this two files. This is my actual code.
Edit: The file can contain more than 1 line of data, usually like 30.
The text cannot be deleted, and the similarity just appear in the end of the text. I mean, the final line of a file text will be always the start of the other file text.
This is for homework and the instruction are: "Read the host file and check if any line is already present in the ip url file, and in case they are not, it is necessary to write them in a temporary file."
#include <stdio.h>
void main()
{
FILE *f1, *f2;
int a, b;
f1 = fopen("D:\\product3\\test.txt","r");
f2 = fopen("D:\\product3\\test2.txt", "r");
if(f1 == NULL || f2 == NULL)
{
printf("Cannot read the files");
}
else
{
a = getc(f1);
b = getc(f2);
while (a != EOF && b != EOF)
{
a = getc(f1);
b = getc(f2);
if(a != b)
{
printf("");
}
}
if (a == b)
{
printf("\n The files are equal \n");
}
else if (a!=b)
{
printf("\n The files aren't equal \n");
}
else
{
printf("\n Error \n");
}
}
fclose(f1);
fclose(f2);
}
The content of the files are:
>Test.txt AAA aaa bbb BBB 111 >Test2.txt AAA aaa bbb BBB 111 333 444 555 6666 777 CCC
so the output must be:
>333 444 555 6666 777 CCC