I'm still learning C programming. But I'm trying to write a program that will compare two text files and then if the two files are different, then tell me where the differences are (like what line, paragraph, etc) and if possible, display the differences.
Using strcmp to compare two text files is easy. It's the other parts that I'd like to know how to be able to do...
My attempt below....
I'm trying to now compare two files, then have program pick up the strings, then if different, display what the strings are. At least, that's my logic if it works.
//compare two files, then report where the differences are.
#include "stdafx.h"
#include <stdio.h>
#include<string.h>
int main()
{
char c1[1000], c2[1000];
//char s1[1000], s2[1000];
FILE *f1;
FILE *f2;
f1 = fopen ("output.txt", "r");
f2 = fopen ("output_copy.txt", "r");
fgets(c1, 1000, f1);
fgets(c2, 1000, f2);
printf("\n");
while((fgets(c1,1000,f1)!= NULL) && (fgets(c2,1000,f2)!= NULL))
{
if(strcmp(c1, c2) != 0)
printf("%s", c1);
printf("%s", c2);
}
printf("\n");
fclose(f1);
fclose(f2);
return 0;
}
Thanks in advance!!

New Topic/Question
Reply




MultiQuote





|