##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# puts

From cppreference.com
< c‎ | io

Defined in header `<stdio.h>` |  |
int puts( const char *str ); |  |

Writes character string `str` and a newline to `stdout`

### [edit] Parameters

str | - | character string to be written

### [edit] Return value

non-negative number on success or EOF otherwise

### [edit] Example

puts() with error checking

Run this code

    #include <stdio.h>
    #include <stdlib.h>

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

        return EXIT_SUCCESS;
    }

Output:

    Hello World

### [edit] See also

fputs | writes a character string to a file stream (function) [edit]
printf fprintf sprintf snprintf (C99) | prints formatted output to stdout, a file stream or a buffer (function) [edit]
C++ documentation for puts

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