gets

Gets a string of characters from stdin and stores them in an array

Local Servers:blocking
Remote Servers:blocking
Classification:ANSI
Platform:NLM
Service:Stream I/O

Syntax

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

Parameters

buf
(OUT) Points to the array into which the characters are to be stored.

Return Values

The gets function returns buf if successful. It returns NULL if a read error occurs.

Remarks

The gets function gets a string of characters from the file designated by stdin and stores them in the array pointed to by buf until a newline character is read. Any newline character is discarded, and a NULL character is placed immediately after the last character read into the array.

It is recommended that fgets be used instead of gets because data beyond the array buf is destroyed if a newline character is not read from the input stream stdin before the end of the array buf is reached.

See Also

fgetc, fgets, fopen, getc, ungetc

gets Example

  #include <stdio.h> 
    
  main ()  
  {  
     char    buffer[80];  
     while (gets (buffer) ) != NULL)  
        puts (buffer);  
  }