Problem comparing struct's record
Posted on 2004-10-27
Hi all, I need to compare 2 records from 2 different structs and would like to know if its possible and if yes, how to do it. I think I've heard you could do it as long as the two struct were define identically...
The problem occurs because I need to format the text to write in a new file. I've sort the informations and now if some item (books in my case) have the same vakue (the same subject in my case), I need to print this information once only. Here's how I thought it could be made. I also tried using the funnction strcmp but it didn't worked.
// We go throught all the books we created
for( i = 0; i < num_books - 1; ++i )
// This is where I need to format
if(i>0 && books[i].subject==books[i--].subject)
// We print onyl the author's name because the subject is identical
fprintf(file_out, "\t\t %s\n", books[i].autor);
// We print both the subject and author's name, it's a new subject category
fprintf(file_out, "%s\t %s\t\n", books[i].subject, books[i].autor);
fprintf(file_out, "\n" );
Also I'd like to know if there's a better way to format the text going in a file, with columns always at the same place, etc.
Computers Smith, Jim
Graphic Animation Black, Tim
Historical Demography 1.0 Young, Mike
Organic science Walters, Jennifer
X Lane, Rick