Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

fputs - Write a string to a file

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

int fputs(const char *s, FILE *fp);

fputs writes the string s to the file with file pointer fp. s must be terminated with a null
byte (\0).

Return val.

0

EOF

if successful.

otherwise.

Notes

In contrast to puts, fputs does not end its output with the addition of a newline character.

The terminating null byte of s is not output.

Control characters for white space (\n, \t, etc.) are converted to their appropriate effect when
output to text files, depending on the type of text file (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

The following program reads strings from file and then outputs them at the display terminal
(SYSOUT).

#include <stdio.h>
int main(void)
{
   FILE *fp_in, *fp_out;
   char s[BUFSIZ];
   int max = 120;
   fp_in = fopen("file","r");
   fp_out = fopen("(SYSOUT)","w");
   while(fgets(s, max, fp_in) != NULL)
     fputs(s, fp_out);
   return 0;
}

See also

fopen, fopen64, puts, fgets