fputs - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# fputs

From cppreference.com
< c‎ | io

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.

### [edit] Parameters

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

### [edit] Return value

Non-negative integer on success, EOF on failure.

### [edit] Example

fputs() with error checking

Run this code

    #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

### [edit] See also

printffprintfsprintfsnprintf (C99) | prints formatted output to stdout, a file stream or a buffer (function) [edit]
puts | writes a character string to stdout (function) [edit]
fgets | gets a character string from a file stream (function) [edit]
C++ documentation for fputs

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/io/fputs&oldid=69908"