Your compiler is very permissive. He should have complained that converting FILE * to char * is invalid.
In any case, assuming the compiler accepts this implicit conversion, the answer is pretty simple. According to the C standard, the char * and void * pointer can hold any value of the pointer without loss. That way you can convert from SOMETYPE * to char * and then back from char * to SOMETYPE *, and you will get the same pointer that you originally had. In fact, on most systems, all pointers are equivalent, and you can freely convert from one to another.
FILE * is a small and opaque pointer type value. The actual pointer to the internal data structure is likely, but it can be implemented in different ways (for example, it can be a UNIX file descriptor converted to a pointer). The STDIO functions simply expect you to use the same opaque FILE * value that you received from fopen in fread / fwrite / fclose.
FILE * converts to char * when assigning filePath. char * converts to FILE * as the first parameter to fgets (again, your compiler must complain), and therefore returns to its original value.
Suggestion: Use a higher level of errors / warnings in your compiler and fix your code.
source share