Open both files for input
Open one file for output
Use two instances of a struct. Each struct will have members like:
Code:
struct record { //define what's in each record
char letr;
int amount;
}rec1, rec2; //and create two instances of this type of struct
Now read through each file, getting one record of data from file #1, and one record of data from file #2. Your logic can be like:
Code:
more1 = fscanf(file_ptr1, "%c, %d", rec1.letr, rec1.amount)
more2 = same as above but for the other file
while (more1 && more2) {
make your comparisons rec1.member to rec2.member
write out your data for matches and mismatches, here
and get more data for another loop
more1 = fscanf( %c, %d, rec1.letr, rec1.amount)
more2 = same as above but for the other file
}
when either file is empty, the remaining data in the non-empty file, will
all be "mismatched" data, so handle that here, until the file with data, is also empty
with another while loop
while(more1)
//run out all the rest of the data, as "mismatched" to your file
while(more2)
//same here, for file2 data.
All this "struct" stuff can be done with just two variables for each file, a char type, and an integer type. Make it clear by their names, which data if from file 1, and which is from file 2. No A and B type variables, make it a1 and a2, and b1 and b2, at least.
If you have 3 or more things for each file that you want to check and compare, then a struct is the only way that makes sense. With only two things, you could use variables, fine.
That's how I'd do it.