• C

comparing two files

I don't know how to solve this problem :
 
Write a program to compare two files , printing the first line where they differ.
 Please help me
LoraAsked:
Who is Participating?
 
deightonConnect With a Mentor progCommented:
#include <stdio.h>
#include<string.h>



main()
{
      FILE *f1,*f2;
      int a=0;
      char buffer1[1001],buffer2[1001];

      if ((f1 = fopen("a:\\file1.txt","r"))==NULL)
      {
            puts("error");
            exit(1);
      }
      if ((f2 = fopen("a:\\file2.txt","r"))==NULL)
      {
            puts("error");
            exit(1);
      }

      while (!feof(f1) && !feof(f2) && a == 0)
      {
            fgets(buffer1,1000, f1);
            fgets(buffer2,1000, f2);
            if (strcmp(buffer1,buffer2))
            {
                  printf("\n%s%s",buffer1,buffer2);
                  a = 1;

            }
      }

      fclose(f1);
      fclose(f2);

      getch();

}
0
 
LoraAuthor Commented:
Can You please help me with this:
 Write a program to print a set of files starting each new one on a new page with a title and a running page count for each file.
0
 
deightonprogCommented:
I've become rather busy.  I'd post it as a new question.

Basically though you need to fopen the file then fgets the records which you can then fprintf to the printer.
0
 
LoraAuthor Commented:
Please answer as soon as possible.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.