How to check if a file exists in C

To check if a file exists in C you can use the follwing snippet.

Sample C

#include <unistd.h>  
  
int fileExists(const char *filename) {  
    return !access(filename, F_OK);  
}  

Please Share us:
Please rate this snippet

One thought on “How to check if a file exists in C

Leave a Reply