cgets

Gets a string of characters directly from the application screen and stores the string.

Library:LibC
Classification:Other
Service:File and Directory I/O

Syntax

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

Parameters

buf

(IN) Points to the array for the string. The first character in the array, buf [0], must be the size of the buffer.

Return Values

Returns a pointer to the start of the string, which is at buf [2]. The second character, buf [1], is the number of characters read.

Remarks

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 null-terminating character, and two additional bytes.

The cgets function reads characters until a carriage-return/line-feed combination is read, or until the specified number of characters is read. The string is stored in the array starting at buf [2]. The carriage-return/line-feed combination, if read, is replaced by a null-terminating character. The actual length of the string read is placed in buf [1].

The cgets function is a hard-wired console function. Even if stdin is redirected, this function only retrieves strings from the console. If your application does not create a screen with the SCREENNAME directive at compile time, your application can receive no input.

For more information on screen creation, see Designating an Application Screen.

See Also