gets(3) CLIX gets(3)
NAME
gets, fgets - Gets a string from a stream
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <stdio.h>
char *gets(
char *s );
char *fgets(
char *s ,
int n ,
FILE *stream );
PARAMETERS
s Points to an array of characters.
n Specifies the number of characters to read.
stream Specifies a stream.
DESCRIPTION
The gets() function reads characters from stdin stream, stdin, into the
array pointed to by s, until a newline character is read or an end-of-file
condition is encountered. The newline character is discarded and the
string is terminated with a null character.
The fgets() function reads characters from the stream into the array
pointed to by s, until n-1 characters are read, or a newline character is
read and transferred to s, or an end-of-file condition is encountered.
The string is then terminated with a null character.
EXAMPLES
1. To read a string from stdin into a buffer:
char s[80];
if (gets(s) == NULL) {
perror("gets");
}
2. To read a set number of characters from an input stream:
2/94 - Intergraph Corporation 1
gets(3) CLIX gets(3)
char s[100];
int number_of_chars=100;
fgets(s, number_of_chars, stdin);
RETURN VALUES
If end-of-file is encountered and no characters have been read, no
characters are transferred to s and a NULL pointer is returned. If a read
error occurs, such as trying to use these functions on a file that has not
been opened for reading, a NULL pointer is returned. Otherwise s is
returned.
RELATED INFORMATION
Functions: ferror(3), fopen(3), fread(3), getc(3), scanf(3), stdio(3)
2 Intergraph Corporation - 2/94