C Standard Library

C <stdio.h> - puts() Function



The C <stdio.h> puts() function writes every character of the null-terminated string pointed to by str and one additional newline character '\n' to the output stream stdout. The terminating null-character is not copied to the stream.

fputs() and puts() are equivalent functions except puts() uses stdout as destination and appends a newline character at the end automatically.

Syntax

int puts ( const char * str );

Parameters

str Specify a null-terminated character string to be written.

Return Value

On success, returns a non-negative value. On failure, returns EOF and sets the error indicator ferror().

Example:

The example below shows the usage of puts() function.

#include <stdio.h>
 
int main (){
  char str[50] = "Hello World!";

  //prints str
  puts(str);
  
  return 0;
}

The output of the above code will be:

Hello World!

❮ C <stdio.h> Library