Syntax
#include <stdio.h> char *gets(char *buffer);Description
gets reads a line from the standard input stream stdin and stores it in buffer. The line consists of all characters up to and including the first new-line character (\n) or EOF. gets then replaces the new-line character, if read, with a null character (\0) before returning the line.
If successful, gets returns its argument. A NULL pointer return value indicates an error or an end-of-file condition with no characters read. Use ferror or feof to determine which of these conditions occurred. If there is an error, the value stored in buffer is undefined. If an end-of-file condition occurs, buffer is not changed.
This example gets a line of input from stdin.
#include <stdio.h> #define MAX_LINE 100 int main(void) { char line[MAX_LINE]; char *result; if ((result = gets(line)) != NULL) { if (ferror(stdin)) perror("Error"); printf("Input line : %s\n", result); } return 0; /**************************************************************************** For the following input: This is a test for function gets. The output should be: Input line : This a test for function gets. ****************************************************************************/ }Related Information