File Input/Output Functions
The
classic functions for
reading from and writing to files are declared in the header file
stdio.h
.
In the descriptions that follow in Table 1-23,
fp designates the file pointer. Those
functions that have no parameter with the file pointer type read from
stdin or write to stdout.
Reading and writing characters and strings
|
Purpose |
Functions |
|
Write a character |
int fputc( int |
|
Read a character |
int fgetc( FILE * |
|
Put back a character |
int ungetc( int |
|
Write a line |
int fputs( const char * |
|
Read a line |
char *fgets( char * |
For each of these input/output functions, there is also a
corresponding function for wide-oriented access. The wide functions
are declared in the header file
wchar.h
(*).
Their names are formed with wc (for wide
character) in place of c (for
character), or with ws (for
wide string) in place of s
(for string).
Block read and write functions
The following file access functions can be used to read or write a block of characters:
-
size_tfwrite( const void *buf, size_tsz, size_tn, FILE *fp); Writes
nobjects of lengthszfrom the buffer addressed bybufto the file.-
size_tfread( void *buffer, size_tsz, size_tn, FILE *fp); Reads up to
nobjects of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access