# implicit declaration of function 'gets' / warning: the `gets' function is dangerous and should not be used

**Code:** `gets` · **Category:** C/C++ · **Seen on:** C, GCC, Clang

`gets()` was removed from the C standard because it cannot limit input size.

## Meaning

C11 deleted it and glibc/compilers warn or refuse. Any input longer than the buffer overflows it, a classic exploit.

## Common causes

- Old tutorial code using gets
- Compiling with `-std=c11` or newer
- Header no longer declares it

## Quick fix

1. Replace with `fgets(buf, sizeof buf, stdin)`
2. Remove the trailing newline manually
3. Use `getline` for unlimited lines

## Detailed fix by platform

### C

1. 

```cpp
fgets(buf, sizeof buf, stdin); buf[strcspn(buf, "
")] = 0;
```


## Code examples

### Replace gets with fgets

```c
char name[32];
gets(name);                         // removed in C11, unsafe
fgets(name, sizeof name, stdin);    // safe
```

## How to diagnose

1. **Standard** — -std flag?
2. **Buffer** — Size known?
3. **Alternative** — fgets/getline?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/gets-removed-implicit-declaration)
