Thanks for all answers, now i have a new question: why whatever i input the output is always GREAT?
Like if the input is not pokemon.csv, then it should returns me "pokemon.csv file is not found. Please enter the name of the file again or enter 1 to exit" instead.
Is there a issue with my fopen format or logic?
int pexists();
int main(){
FILE *pokemon;
int rc = 0;
char file_name[30];
printf("Please enter the NAME of the file that containing the Pokemon descriptions:\n");
scanf("%c", file_name);
rc = pexists();
return 0;
}
/*********************************************************************/
//function that do the exist checking.
int pexists(){
FILE *pokemon;
//int rc = 0;
// open the file by reading.
pokemon = fopen("file_name", "r");
if(!pokemon){
printf("Pokemon file is not found. Please enter the name of the file again or enter 1 to exit.\n");
exit(1);
}
else{
printf("GREAT\n");
}
fclose(pokemon);
}