I'm attempting to open a file in a C application. How do I check that a file exists before trying to read from it?
Try to open it:
FILE * file;
file = fopen("file_name", "r");
if (file){
//file exists and can be opened
//...
// close file when you're done
fclose(file);
}else{
//file doesn't exists or cannot be opened (es. you don't have access permission)
}
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