0

I have been trying to compare string from .txt file to string. I found that i can use strcmp but its not working. Imagine that in input.txt i have only string "HERO".

int main(){
    FILE* file;
    char load[50];
    int value;
    file = fopen("input.txt", "r");

    while (fgets(load, sizeof load, file) != NULL){
        value = strcmp(load, "HERO");
        if (value == 0){
            printf("strings are same.");
        }
        else{
            printf("strings are not same.");
        }

}

I have read that if they are same strcmp should return 0, but it returns -1

sccc444
  • 33
  • 4

0 Answers0