#include <stdio.h> #include <io.h> #include <alloc.h> #include <string.h> #ifndef __cplusplus typedef enum { false, true } bool; #endif bool FileCompare(const char *FileName1, const char *FileName2) { FILE *fpFile1, *fpFile2; char *str1, *str2; bool result; fpFile1 = fopen(FileName1, "rt"); if(!fpFile1) return false; fpFile2 = fopen(FileName2, "rt"); if(!fpFile2) { fclose(fpFile1); return false; } if(filelength(fileno(fpFile1)) != filelength(fileno(fpFile2))) { fclose(fpFile1); fclose(fpFile2); return false; } str1 = (char *)malloc(sizeof(char) * 1024); str2 = (char *)malloc(sizeof(char) * 1024); result = true; while(fgets(str1, 1024, fpFile1) && fgets(str2, 1024, fpFile2)) if(strcmp(str1, str2)) { result = false; break; } fclose(fpFile1); fclose(fpFile2); free(str1); free(str2); return result; } void main(int ArgC, char *ArgV[]) { puts("Comparador de arquivos. by Wenderson Teixeira"); if(ArgC < 3) { puts("Uso: filecomp arquivo1.ext arquivo2.ext"); return; } if(FileCompare(ArgV[1], ArgV[2])) puts("Arquivos são iguais."); else puts("Arquivos são diferentes."); }