Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

puts - Output a string to the standard output

&pagelevel(4)&pagelevel

Definition   

#include <stdio.h>

int puts(const char *s);

puts writes the string s to the standard output stdout and adds to it a terminating newline character.
s must be terminated with a null byte (\0)

Return val.

0

if successful.                


EOF

otherwise.

Notes

In contrast to fputs, puts automatically terminates output with a newline character. If the string to be output already contains a terminating newline (e.g. a record in SAM or ISAM files), an additional blank line will be inserted on output.

The terminating null byte of s is not output.

For further information on output to text files and on converting the control characters for white space (\n, \t, etc.) see section “White space” (Basic terms).

The following applies in the case of text files with SAM access mode and variable record length for which a maximum record length is also specified: When the specification split=no was entered for fopen, records which are longer than the maximum record length are truncated to the maximum record length when they are written. By default or with the specification split=yes, these records are split into multiple records. If a record has precisely the maximum record length, a record of the length zero is written after it.

Example

This example shows how puts and fputs differ in the way in which they terminate the output.

#include <stdio.h>
int main(void)
{
 FILE *fp;
 char s[BUFSIZ];
 fp=fopen("file","w");
 while(gets(s) != NULL)
      {
        fputs(s,fp);
        puts(s);
      }
 return 0;
}

If you look at file after this program has run, you will see that the strings from the input (gets deletes any existing newline) of fputs were written one following another and not by lines.
In contrast, the output with puts is effected line by line, since a newline is automatically appended to every string that is read.

See also

fputs, gets, fgets, putws, sprintf, snprintf