Check IF file exists or not - C, C++ Programming Language 0 Check IF file exists or not - C, C++ Programming Language masoomyf 11:27 PM Share to Facebook Share to Twitter Share to Reddit Share to Pinterest Share to WhatsApp Share to LinkedIn Share to Email 0 This may be the best way for checking if a file exists or not. #include #include #include int exists(const char *filename); void main() { int a=2; a= exists("c:\m.txt"); if(a==0) { printf("File Exists"); }else{ printf("File Not Exists"); } } int exists(const char *filename) { FILE *file; if (file = fopen(filename, "r")) { fclose(file); return 0; // if file exists it return 0. } return 1; // if file not exists it return 1. } Comments