Use fclose() instead of close() for file pointers.