Check file extension in C

Don’t forget to define true and false constants.

#define TRUE 1
#define FALSE 0
int is_exe_extension(const char *filename)
{
    char *ext = strrchr(filename, '.');
    if (!ext)
        return FALSE;
    else
    {
        if(strcmp("exe", ext + 1) == 0)
            return TRUE;
        return FALSE;
    }
}
Categories: C Tags: , , ,
%d bloggers like this: