char* gets( char* str );
(1) (removed in C11)char* gets_s( char* str, rsize_t n );
(2) (since C11) 1)Reads
stdininto the character array pointed to by
struntil a newline character is found or end-of-file occurs. A null character is written immediately after the last character read into the array. The newline character is discarded but not stored in the buffer.
2)Reads characters from
stdinuntil a newline is found or end-of-file occurs. Writes only at most
n - 1characters into the array pointed to by
str, and always writes the terminating null character (unless
stris a null pointer). The newline character, if found, is discarded and does not count toward the number of characters written to the buffer.
The following errors are detected at runtime and call the currently installed
constraint handlerfunction:
In any case,
gets_s
first finishes reading and discarding the characters from
stdinuntil new-line character, end-of-file condition, or read error before calling the constraint handler.
As with all bounds-checked functions,
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 constant
1before including
<stdio.h>.
[edit] Parameters str - a character array the characters from stdin to be written to n - maximum number of characters that can be written to the array pointed to by str [edit] Return valuestr on success, a null pointer on failure.
If the failure has been caused by end of file condition, additionally sets the eof indicator (see feof()) on stdin. If the failure has been caused by some other error, sets the error indicator (see ferror()) on stdin.
[edit] NotesThe gets()
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 on stdin
). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard. fgets() and gets_s()
are the recommended replacements.
WARNING: Never use gets()
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4