HP C/iX Library Reference Manual (30026-90004)
Chapter 5 203
HP C/iX Library Function Descriptions
gets
gets
Reads a string from the standard input stream stdin.
Syntax
#include <stdio.h>
char *gets (char *
s
);
Parameters
s
A pointer to a character array where the string is to be returned.
Return Values
x A pointer to the character array.
NULL An error occurred. If any characters were read, the array contents are
indeterminate.
Description
The gets function reads a string from the standard input stream, stdin, and stores the
string in a character array pointed to by
s
. The string terminates by a new line in the
input, which gets() replaces with a null character in the array or when end-of-file is
reached.
Example
The following example uses gets() and puts().
#include <stdio.h>
main()
{
char line[80], *gets();
while((gets(line)) != NULL)
puts(line);
}
To terminate this program, generate an end of file on stdin. Using string comparison and
string length functions, you can write a termination condition for this program.
See Also
ferror(), fopen(), fread(), getc(), puts(), scanf(), ANSI C 4.9.7.7, POSIX.1 8.1