I am wondering, how to check if I am opening file which exists with fopen? I want to diplay some message, when user selects file with bad name. Is must be some simple checking, but I am not able to solve it.
Thanks
in your param list:
FILE pFile ;
then:
pFile = fopen ("myfile.txt","r");
if (pFile == NULL)
printf("No Such File !! ");
When fopen
fails, it returns NULL
and sets errno
to indicate the type of error.
Check the return value, and if it's NULL
check errno
. You can use functions like perror
or strerror
to display simple messages about those errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With