Use C puts function to write string to standard output

Syntax

C puts function has the following syntax.

int puts(const char *str);

C puts function is from header file stdio.h.

Description

C puts function writes the string to the standard output device. The null terminator is translated to a newline.

C puts function returns a nonnegative value on success or an EOF upon failure.

Example

Write string to standard output using C puts function.


#include <stdio.h>
#include <string.h>
/*w  w w .  j ava2 s.  c om*/
int main(void)
{
  char str[80];

  strcpy(str, "this is an example");

  puts(str);

  return 0;
}

The code above generates the following result.


puts() function is a simplified version of the printf() function.

puts() displays a string of text without all printf()'s formatting magic. puts() always displays the newline character at the end of its output.


#include <stdio.h>
 /*from  w  w w . j  a va 2s  . co  m*/
int main()
{
    puts("error.");
    return(0);
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h