| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <stdio.h> | ||
char* gets(char* str); | (1) | (removed in C11) |
char* gets_s(char* str, rsize_t n); | (2) | (since C11) |
gets_s first finishes reading and discarding the characters fromstdin until new-line character, end-of-file condition, or read error before calling the constraint handler.gets_s is only guaranteed to be available if__STDC_LIB_EXT1__ is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT1__ to the integer constant1 before including<stdio.h>.Contents |
| str | - | a character array the characters fromstdin to be written to |
| n | - | maximum number of characters that can be written to the array pointed to bystr |
str on success, a null pointer on failure.
If the failure has been caused by end of file condition, additionally sets theeof indicator (seefeof()) onstdin. If the failure has been caused by some other error, sets theerror indicator (seeferror()) onstdin.
Thegets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear onstdin). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard.fgets() andgets_s() are the recommended replacements.
WARNING: Never usegets().
(C11)(C11)(C11) | reads formatted input fromstdin, a file stream or a buffer (function)[edit] |
| gets a character string from a file stream (function)[edit] | |
| writes a character string to a file stream (function)[edit] | |
(dynamic memory TR) | read from a stream into an automatically resized buffer until delimiter/end of line (function)[edit] |
C++ documentation forgets | |