Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
So far, you've learned how to open a file using fopen() and how to read from a file using fgetc(). You've seen, once again, that you can often use two different functions to solve the same problem. Now let's look at some functions that allow you to write data out to a file.
The Standard Library offers several functions that write data out to a previously opened file. This section will introduce three of them: fputc(), fputs(), and fprintf().
fputc() takes an int holding a character value and writes the character out to the specified file. fputc() is declared as follows:
int fputc( int c, FILE *fp );
If fputc() successfully writes the character out to the file, it returns the value passed to it in the parameter c. If the write fails for some reason, fputc() returns the value EOF.