Puts c function – puts C Library Function

Puts in c: The function int puts(const char *str); writes a null terminated string pointed by str to the standard output(stdout) stream and appends a newline character(‘\n’).

Function prototype of puts

int puts(const char *str);
  • str : This is the pointer to a C string to be written on stdout stream.

Return value of puts

C puts(): On Success, puts function returns a non-negative value otherwise returns EOF in case of an error.

C program using puts function

Puts c function: The following program shows the use of puts function to write a string on console.

puts C Library Function

#include <stdio.h>
 
int main(){
   char string[50];
 
   printf("Enter your name\n");
   gets(string);
 
   printf("You name is : ");
   puts(string);
    
   return(0);
}

Output

Enter your name
Jack Dawson
You name is : Jack Dawson