Easy Tutorial
❮ C Function Gmtime C Function Isgraph ❯

C Library Function - gets()

C Standard Library - <stdio.h>

Description

The C library function char *gets(char *str) reads a line from the standard input stdin and stores it into the string pointed to by str. It stops when either a newline character is read or when the end-of-file is reached, whichever comes first.

Declaration

Here is the declaration for the gets() function.

char *gets(char *str)

Parameters

Return Value

On success, the function returns str. If an error occurs or if end-of-file is reached while no characters have been read, it returns NULL.

Example

The following example demonstrates the use of the gets() function.

#include <stdio.h>

int main()
{
   char str[50];

   printf("Please enter a string: ");
   gets(str);

   printf("The string you entered is: %s", str);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

Please enter a string: tutorialpro
The string you entered is: tutorialpro

C Standard Library - <stdio.h>

❮ C Function Gmtime C Function Isgraph ❯