5.5 FORMATTED I/O FUNCTIONS
Formatted I/O functions are used to read or write any type of data (char, int, float, string, etc.) from a
file. These functions behave like console I/O functions—scanf( ) and printf( ). The only difference is
that the formatted I/O functions are used for files now.
Writing Data to a File
For writing formatted
output from a file, we use the fprintf( ) function:
Syntax
fprintf(fp, “format string”, list);
where fp is a
file pointer
;
format strings
are %c for char, %d for int, or %f for float; and
list
is
the number of variables to be written to a file.
Reading Data from a File
For reading formatted
data from a file, we use the fscanf( ) function:
Do'stlaringiz bilan baham: