fclose() Function
To close a file you need to use the fclose function, fclose returns zero if the file is closed successfully.
int fclose(FILE *a_file);
Note that it's possible for fopen to fail even if your program is perfectly correct: you might try to open a file specified by the user, and that file might not exist (or it might be write-protected). In those cases, fopen will return 0, the NULL pointer.
fclose(fp);