comparing two files

Posted on 2000-03-02
Last Modified: 2010-04-15
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
Question by:Lora
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 18

Accepted Solution

deighton earned 50 total points
ID: 2575918
#include <stdio.h>

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

      if ((f1 = fopen("a:\\file1.txt","r"))==NULL)
      if ((f2 = fopen("a:\\file2.txt","r"))==NULL)

      while (!feof(f1) && !feof(f2) && a == 0)
            fgets(buffer1,1000, f1);
            fgets(buffer2,1000, f2);
            if (strcmp(buffer1,buffer2))
                  a = 1;





Author Comment

ID: 2575969
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.
LVL 18

Expert Comment

ID: 2576026
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.

Author Comment

ID: 2576234
Please answer as soon as possible.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question