gets(3C)
_________________________________________________________________
gets function
Read from the standard input file until encountering anew line.
_________________________________________________________________
Calling Sequence
char *stringbuf, *gets();
gets(stringbuf);
where stringbuf is a pointer to a user-provided character
array.
Description
Use the gets function to read from the standard input file. This
function removes New Line from the line, unlike fgets, which
includes it. This routine is provided strictly for compatibility
with previous versions of the C language. You might want to use
the fgets function instead, because with it you can use one of
the parameters to set a maximum limit of characters to read.
With the gets function you cannot specify a limit.
The include file stdio.h defines the gets function.
Returns
The gets function returns a null on end of file or error;
otherwise it returns the pointer to the buffer.
Related Functions
See also the getc, getchar, fgets, and dg_fgets functions.
Example
/* Program test for the gets() function */
#include <stdio.h>
#define STRMAX 80
char stringbuf[STRMAX], *gets();
int last, strlen();
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
gets(3C)
main() {
printf("? ");
gets(stringbuf);
printf("Length of your string = %d.\n",
last = strlen(stringbuf));
}
A response to the ? prompt of
? This string may be a little longer than you thought.
generates the output
Length of your string = 52.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)