Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 10: Working with Files > Working with Files: Writing Files

Working with Files: Writing Files

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.

Writing 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.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint