this program is used to see weather the two entered files are same or not.Note that this program is created and there is no inbuilt functions are used to check weather two files are equal or not.In this program I have declared two file variables and two character variables.And this program will return that from which character two files will differ from each other.then I have opened that two files and in if condition i have informed that if c1==c2 means character1 is equal to character2 then get next characters from both files else print the character number from which they becomes different.FURTHER RUN THIS PROGRAM ON YOUR COMP. FOR BETTER UNDERSTANDING OR CREATE IT.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
FILE *f1;
FILE *f2;
char c1,c2;
char fn1[300],fn2[300];
int ch=0;
clrscr();
printf("Enter first file name: ");
scanf("%s",&fn1);
printf("\nEnter Second file name: ");
scanf("%s",&fn2);
f1=fopen(fn1,"r");
f2=fopen(fn2,"r");
c1=fgetc(f1);
c2=fgetc(f2);
while(c1!=EOF)
{
if(c1==c2)
{
ch++;
c1=fgetc(f1);
c2=fgetc(f2);
}
else
{
printf("Files differ from %d th character",ch);
goto END;
}
}
printf("Files are Same");
END:
getch();
}
Program:
#include<stdio.h>
#include<conio.h>
main()
{
FILE *f1;
FILE *f2;
char c1,c2;
char fn1[300],fn2[300];
int ch=0;
clrscr();
printf("Enter first file name: ");
scanf("%s",&fn1);
printf("\nEnter Second file name: ");
scanf("%s",&fn2);
f1=fopen(fn1,"r");
f2=fopen(fn2,"r");
c1=fgetc(f1);
c2=fgetc(f2);
while(c1!=EOF)
{
if(c1==c2)
{
ch++;
c1=fgetc(f1);
c2=fgetc(f2);
}
else
{
printf("Files differ from %d th character",ch);
goto END;
}
}
printf("Files are Same");
END:
getch();
}