Syntax (closing a file): fclose (fp);
where fp is a file pointer associated with a file which is to be closed. Always close any file that
you open. It is a good programming practice.
File input/output (I/O) operations are of different types as categorized below in
Figure 5.1
.
Figure 5.1 File I/O Operations 5.2 CHARACTER INPUT/OUTPUT WITH FILES Just as we can read and write data from the keyboard using getchar( ) and putchar( ) functions, we can
read or write one character at a time using character I/O functions.
Writing to a File Before writing to a file we must open it in write mode.
Syntax fputc (ch, fp); where ch is a
character variable or constant and fp is a
file pointer. Reading Data from a File The data that is written into a file can also be read from the same file using the fgetc( ) function.