| |
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. |
| April 04, 2009 14:48:20 |
#4 |
| iantuy |
Member Since: October 2008 Total Comments: 2 |
RE: Compare Two Files in C |
int main(int argc, char* argv[]) { if(argc!=3) return -1; FILE *fp1, *fp2; fp1 = fopen(argv[1],"r"); fp2 = fopen(argv[2],"r"); if(!fp1 || !fp2) return -1; while(fgetc(fp1) == fgetc(fp2) && !feof(fp1)); return feof(fp1)&&feof(fp2)?0:1; } |
| |
Back To Question | |