fputs

Defined in header <stdio.h>
int fputs( const char          *str, FILE          *stream );
(until C99)
int fputs( const char *restrict str, FILE *restrict stream );
(since C99)

Writes given null-terminated character string to the given output stream.

Parameters

str - null-terminated character string to be written
stream - output stream

Return value

Non-negative integer on success, EOF on failure.

Example

fputs() with error checking.

#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    int ret_code = fputs("Hello World",stdout);
    if ((ret_code == EOF) && (ferror(stdout)))   /* test whether EOF was reached */
    {
       perror("fputs()");
       fprintf(stderr,"fputs() failed in file %s at line # %d\n", __FILE__,__LINE__-4);
       exit(EXIT_FAILURE);
    }
 
    return EXIT_SUCCESS;
}

Output:

Hello World

References

  • C11 standard (ISO/IEC 9899:2011):
    • 7.21.7.4 The fputs function (p: 331-332)
  • C99 standard (ISO/IEC 9899:1999):
    • 7.19.7.4 The fputs function (p: 297)
  • C89/C90 standard (ISO/IEC 9899:1990):
    • 4.9.7.4 The fputs function

See also

prints formatted output to stdout, a file stream or a buffer
(function)
writes a character string to stdout
(function)
gets a character string from a file stream
(function)
C++ documentation for fputs
doc_C_Language
2016-10-10 18:35:18
Comments
Leave a Comment

Please login to continue.