dimanche 6 décembre 2015

If-else statement with FILE i/o in C

I'm trying to make an if-else statement with some basic file i/o. Here's my code:

FILE *fPointer1;

char file1[20], file2[20];

printf("Please enter the name of the first file:\n");
gets(file1); 

if (file1 == "fileone.txt") {
    fPointer1 = fopen("fileone.txt", "r");
}
else {
    printf("ERROR. Cannot find that file.");
}

fclose(fPointer1);

return 0;

}

When I open the program, even if I type the correct filename it still displays my error message in the 'else' of my if statement. Thank you for your time :)

Aucun commentaire:

Enregistrer un commentaire