| Defined in header <stdio.h> | ||
|---|---|---|
int puts( const char *str ); |
Writes character string str and a newline to stdout.
Parameters
| str | - | character string to be written |
Return value
non-negative number on success or EOF otherwise.
Example
puts() with error checking.
#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
References
- C11 standard (ISO/IEC 9899:2011):
- 7.21.7.9 The puts function (p: 333)
- C99 standard (ISO/IEC 9899:1999):
- 7.19.7.10 The puts function (p: 299)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.9.7.10 The puts function
See also
| writes a character string to a file stream (function) | |
| (C99)(C11)(C11)(C11)(C11) | prints formatted output to stdout, a file stream or a buffer (function) |
C++ documentation for puts | |
Please login to continue.