I've written a function that compares two different files and it prints if they're equal or not. The problem is that the files are the same and at some point it returns as FAILED.
void comparar_conteudo(){
for(int i = 1; i <= 10; i++){
int bp = 0;
char ficheiro1[100] = "saida/command";
char ficheiro2[100] = "expected/exp_query";
char commandString[2]; sprintf(commandString, "%d", i);
strcat(ficheiro1, commandString); strcat(ficheiro2, commandString);
strcat(ficheiro1, "_output.txt"); strcat(ficheiro2, ".txt");
FILE *novoFile1 = fopen(ficheiro1, "r");
FILE *novoFile2 = fopen(ficheiro2, "r");
char* line1 = malloc(sizeof(char));
char* line2 = malloc(sizeof(char));
while(fgets(line1, 1024, novoFile1)){
fgets(line2, 1024, novoFile2);
if(strcmp(line2,line1) != 0){
bp = 1;
break;
}
}
if(bp == 0)
printf("Query %d: SUCCESS\n", i);
else
printf("Query %d: FAILED\n", i);
fclose(novoFile1);
fclose(novoFile2);
free(line1);
free(line2);
}
}
once you did this
char* line1 = malloc(sizeof(char));
char* line2 = malloc(sizeof(char));
while(fgets(line1, 1024, novoFile1)){
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.