On this page
gets
Prev: sprintf | Up: stdio.h | Next: scanf
Rel: fgets(), stdio.h, stdio.h & File I/O Guide
Ref: cppreference — gets
Tags: #public #prog #c #stdlib #stdio #tier/legacy
Include
#include <stdio.h>
Signature & Overview
char *gets(char *str); /* REMOVED in C11 */
Reads a line from stdin with zero bounds checking; removed from ISO C11.
Legacy / Avoid: Prefer fgets() in all new code.
Notes & Pitfalls
- Removed in C11 due to guaranteed buffer-overflow vulnerability: Never use
gets()—always usefgets(buf, sizeof(buf), stdin).
Example
#include <stdio.h>
int main(void) {
char buf[64];
// Safe replacement for removed gets():
if (fgets(buf, sizeof(buf), stdin)) { /* process buf */ }
}
Linked from
Related notes
- tuts/c/stdlib/stdio/scanf Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/sprintf Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio/fgets Linked here; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/fclose shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/feof shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/ferror shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fflush shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fopen shared tags: #c, #prog, #stdio, #stdlib, #tier