gets Function

Get a string from stdin.

Include

<stdio.h>

Prototype

char *gets(char *s);

Argument

s
pointer to the storage string

Return Value

Returns a pointer to the string s if successful; otherwise, returns a null pointer.

Remarks

The function reads characters from the stream stdin and stores them into the string pointed to by s until it reads a newline character (which is not stored) or sets the end-of-file or error indicators. If any characters were read, a null character is stored immediately after the last read character in the next element of the array. If gets sets the error indicator, the array contents are indeterminate.

Example

#include <stdio.h>

int main(void)
{
  char y[50];

  gets(y) ;
  printf("Text: %s\n", y);
}

Example Input

Contents of UartIn.txt (used as stdin input for simulator):

Short
Longer string

Example Output

Text: Short