Solved

comparing two files

Posted on 2000-03-02
4
184 Views
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
0
Comment
Question by:Lora
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 50 total points
ID: 2575918
#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
 

Author Comment

by:Lora
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.
0
 
LVL 18

Expert Comment

by:deighton
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.
0
 

Author Comment

by:Lora
ID: 2576234
Please answer as soon as possible.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Retrun object in plist format 5 63
SQL handling single and double quotes 3 96
C language IDE – Compilers installation 14 72
convert char array to number in c 5 85
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

831 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