GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C

 Print  |  
Question:  Compare Two Files in C

Answer: Write a program that compares two files and return 0 if they are equal and 1 if they are not equal.


March 03, 2009 08:33:10 #3
 monuavi26   Member Since: March 2009    Total Comments: 2 

RE: Compare Two Files in C
 
/* consider both the files have 15 characters*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmpfiles(void);
void main()
{
int result =cmpfiles();
printf("tn %d",result);
}

int cmpfiles(void)
{
FILE *fp1.*fp2;
fp1 = fopen(file1,'r'); // open the file1 to read its content
fp2 = fopen(file1,'r'); // open the file2 to read its content

char c1[15],c2[15]; //declaring a string to hold the content of each file

fgets(c1,16,fp1); //reading the content of file1 into c1
fgets(c2,16,fp2);//reading the content of file2 into c2

if(strcmp(c1,c2) = = 0)
 {
   return 1;
}

else return 0;
}
     

 

Back To Question