C puts() Function Tutorial

In this section, we will learn what the puts() function is and how to use it in C.

puts() Function in C

The `puts` function is used to send character-strings into the output stream.

Note:

  • The function will drop the null-character of the character-string and instead it will append a newline character.

puts() Function Syntax

int puts(const char *str)

puts() Function Parameters

This function takes the address (pointer) of a character-string that we want to send to output as its argument.

puts() Function Return Value

The return value of this function will be a non-negative value on successful operation and EOF if the operation failed for whatever reason.

Example: using puts() function in C

#include <stdio.h>
int main() {

    char array[30];

    puts("Please enter something:");
    gets(array);

    puts("You've entered:");
    puts(array);

    return 0;
}

Output;

Please enter something:

My name is John

You've entered:

My name is John
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies