Is there a better way than simply trying to open the file?
int exists(const char *fname) { FILE *file; if ((file = fopen(fname, \"r\"))) {
FILE *file; if((file = fopen("sample.txt","r"))!=NULL) { // file exists fclose(file); } else { //File not found, no memory leak since 'file' == NULL //fclose(file) would cause an error }