Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

gets - Read a string from standard input

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

char *gets(char *s);

gets reads characters from the standard input stdin until the next newline and stores the
string in the area pointed to by s, replacing the newline with the null byte (\0).

Return val.

Pointer to the result string

if successful. gets terminates the string with the null byte (\0).

NULL pointer

if end of file is reached or a read error occurs.

Notes

You must explicitly provide the area in which gets is to store the string read!

In contrast to fgets, gets deletes a read newline character, i.e. overwrites it with the null
byte.

You can satisfy the EOF condition when reading from the terminal by means of the following
actions:
pressing the K2 key and entering the system commands EOF and RESUME-PROGRAM.

Example

The following program reads strings from the standard input and writes them to the
standard output. The reading can be terminated with the K2 key and the EOF and
RESUME-PROGRAM commands.

#include <stdio.h>
int main(void)
{
 char s[BUFSIZ];
 while(gets(s) != NULL)
      puts(s);
 return 0;
}

See also

fgets, puts, fputs, getws