when some amount of data is to be stored in a file, the file is organized in the form of a table with rows representing records and columns representing fields.
The C language treats files as just a stream of characters and accordingly allows input and output in strings of characters.
Functions re available for single character as well as multiple character I/O from files.
FILE is a datatype defined in the header file stdio.h.
The standard library function used for opening a file in C is fopen (file-nane, mode)
Mode specifies the way in which a file is to be opened, There are 6 modes in which a file can be opened –
read-only
write-only
append
read + write
write + read
read + append
Two functions – fgetc() and fputc facilitate character I/O with files
EOF is a constant defined in the header file stdio.h, it indicates end of file.
fopen (), when unsuccessful, returns a NULL value.
The function fclose () is used to close opened files.
stdin, stdout and stderr are FILE type pointers declared in the header tile stdio.h. They refer to the standard input device(keyboard), standard output device(VDU) and standard error device(VDU) respectively.
Two functions facilitate line VO with files – fgetc() fputc()
The Two functions fprintf() and fscanf() facilitate formatted /O with files. They are similar to printf() and scanf (). but for one additional parameter, the file pointer.
Random access in files is possible with the function fseek() .
The function rewind () positions the pointer at the beginning of the file.
Whole records can be read from or written into a file using the functions fread() and fwrite().