You probably have a new line on the end of "filename", since fgets() also reads in the new line character.

You can remove it as such:


char * nl = NULL;

/* ... */
nl = strchr(filename,...