Check if file exists in C

Don’t forget to define true and false constants.

#define TRUE 1
#define FALSE 0
int file_exists(const char *filename)
{
    FILE *file = fopen(filename, "r");
    if (file)
    {
        fclose(file);
        return TRUE;
    }
    return FALSE;
}
Categories: C Tags: , , ,
%d bloggers like this: