[Previous]
[Contents]
[Next]

cgets()

get a string of characters directly from the console

Synopsis:

#include <conio.h>
char *cgets( char *buf );

Description:

The cgets() function gets a string of characters directly from the console, and stores the string and its length in the array pointed to by buf. The first element of the array, buf[0], must contain the maximum length in characters of the string to be read. The array must be big enough to hold the string, a terminating null character, and two additional bytes.

The cgets() function reads characters until a newline character is read, or until the specified number of characters is read. The string is stored in the array starting at buf[2]. The newline character, if read, is replaced by a null character. The actual length of the string read is placed in buf[1].

Returns:

A pointer to the start of the string, which is at buf[2].

Examples:

#include <conio.h>

void main()
  {
    char buffer[82];

    buffer[0] = 80;
    cgets( buffer );
    cprintf( "%s\r\n", &buffer[2] );
  }

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

fgets(), getch(), getche(), gets()


[Previous]
[Contents]
[Next]