C Programming language

C - File Operation : Close a File
Previous Home Next

When we have finished reading from the file, we need to close it. This is done using the function fclose() through the statement.

fclose ( fp ) ;

Once we close the file we can no longer read from it using getc() unless we reopen the file.

Declaration of fclose( ) Function
int fclose(FILE * fptr); // The fclose() function is used for closing opened files. The only argument it accepts is the file pointer.
File modeDescription
rOpen a text file for reading
wCreate a text file for writing, if it exists, it is overwritten
aOpen a text file and append text to the end of the file
rbOpen a binary file for reading
wbCreate a binary file for writing, if it exists, it is overwritten
abOpen a binary file and append data to the end of the file
Previous Home Next