File I/O: fprintf(), fscanf(), fgets(), and fputs()

For each of the I/O functions in the preceding chapters, there is a similar file I/O function. The main distinction is that you need to use a FILE pointer to tell the new functions with which file to work. Like getc() and putc(), these functions require that you identify a file by using a pointer-to-FILE such as stdout or that you use the return value of fopen().

The fprintf() and fscanf() Functions

The file I/O functions fprintf() and fscanf() work just like printf() and scanf(), except that they require an additional first argument to identify the proper file. You've already used fprintf(). Listing 13.3 illustrates both of these file I/O functions along with the rewind() function.

Listing ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.