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 - get string from standard input stream

&pagelevel(4)&pagelevel

Syntax

#include <stdio.h>

char *gets(char *s); 

Description

gets() reads bytes from the standard input stream into the array pointed to by s until a newline is read or an end-of-file condition is encountered. A newline character, if any, is overwritten by a null byte.

gets() can mark the structure component st_atime for the file to which stream is assigned for changing (see sys/stat.h). The structure component st_atime is updated as soon as fgetc()fgets(), fgetwc(), fgetws(), fread(), fscanf(), getc(), getchar(), gets() or scanf() are called successfully for stream and return data which is not was not provided by a preceding call to ungetc() or ungetwc().

Return val.

Pointer to the result string


upon successful completion. gets() terminates the string with a null byte.

Null pointer

if the stream is at end-of-file. The end-of-file indicator for the stream is set; errno is not set.

If a read error occurs. The error indicator for the stream is set, and errno is set to indicate the error.

Errors

See fgetc().

Notes

Reading a line that overflows the array pointed to by s causes undefined results. The use of fgets() is recommended.

If gets() is reading from the standard input stdin in the POSIX environment, and EOF is the end criterion for reading, the EOF condition can be achieved by the following actions:

BS2000
If fgetc() is reading from the standard input stdin in the BS2000 environment, and EOF is the end criterion for reading, the EOF condition can be achieved by means of the following actions at the terminal:

  1. by pressing the [K2] key.

  2. by entering the system commands EOF and RESUME-PROGRAM. (End)

The program environment determines whether gets() is executed for a BS2000 or POSIX file.

>

on a block-special terminal: by entering the key sequence [@][@][d]

>

on a character-special terminal: by entering [CTRL]+[D]

See also

feof(), ferror(), fgets(), stdio.h.