I would put the fclose inside your ( != NULL) conditional also, otherwise your application may end up tryng to close a NULL pointer (which several OS's don't like you doing).