CGETS(DOS) XENIX System V CGETS(DOS)
Name
cgets - Gets a string.
Syntax
#include <conio.h>
char *cgets (str);
char * str;
Description
The cgets function reads a string of characters directly
from the console and stores the string and its length in the
location pointed to by str. The str must be a pointer to a
character array. The first element of the array, str[0],
must contain the maximum length (in characters) of the
string to be read. The array must have enough elements to
hold the string, a terminating null character ('\0'), and
two additional bytes.
cgets continues to read characters until a carriage
return/linefeed combination (CR-LF) is read, or the
specified number of characters have been read. The string is
stored starting at str[2]. If a CR-LF combination is read,
it is replaced with a null chracter ('\0') before being
stored. cgets then stores the actual length of the string in
the second array element, str[1].
Return Value
cgets returns a pointer to the start of the string, which is
at str[2]. There is no error returned.
See Also
getch(DOS), getche(DOS)
Page 1 (printed 8/7/87)
CGETS(DOS) XENIX System V CGETS(DOS)
Example
#include <conio.h>
char buffer[82]; char *result; int numread;
.
.
. *buffer = 80; /* maximum number of chracters */
/* note that *buffer is equivalent
** to buffer[0]
*/ /* The following statements input a string
from the ** keyboard and find its length. */
result = cgets(buffer); numread = buffer[1];
/* Result points to the string, and numread is its ** length
(not counting the carriage return, which has ** been
replaced by a null chracter). */
Notes
This call must be compiled with the -dos flag.
Page 2 (printed 8/7/87)