Next: Line-Oriented Input, Previous: Opening and Closing Files, Up: C-Style I/O Functions

#### 14.2.2 Simple Output

Once a file has been opened for writing a string can be written to the file using the `fputs` function. The following example shows how to write the string ‘`Free Software is needed for Free Science`’ to the file ‘`free.txt`’.

         filename = "free.txt";
         fid = fopen (filename, "w");
         fputs (fid, "Free Software is needed for Free Science");
         fclose (fid);

— Built-in Function: fputs (fid, string)

> Write a string to a file with no formatting.

> Return a non-negative number on success and EOF on error.

> See also: scanf, sscanf, fread, fprintf, fgets, fscanf.

A function much similar to `fputs` is available for writing data to the screen. The `puts` function works just like `fputs` except it doesn't take a file pointer as its input.

— Built-in Function: puts (string)

> Write a string to the standard output with no formatting.

> Return a non-negative number on success and EOF on error.