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

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

Exact message you may see the `gets' function is dangerous and should not be usedimplicit declaration of function 'gets'gets was not declareduse of undeclared identifier 'gets'
Seen on: C GCC Clang

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

"x" can't be opened because it is from an unidentified developer — macOS: “app” can’t be opened because it is from an unidentified developer (macOS)"x" can't be opened b…0x800704EC — 0x800704EC: This program is blocked by group policy (Windows Defender) (Windows)0x800704ECApple could not verify "x" is free of malware — macOS: “app” cannot be opened because Apple cannot check it for malicious software / Apple could not verify “app” is free of malware that may harm your Mac (macOS)Apple could not verif…avc: denied — SELinux is preventing ... / avc: denied { read } for pid=... (permission denied despite correct permissions) (Linux)avc: deniedCredSSP encryption oracle remediation — Remote Desktop: An authentication error has occurred. The function requested is not supported. This could be due to CredSSP encryption oracle remediation (Windows)CredSSP encryption or…implicit declaration of function — C: warning: implicit declaration of function 'foo' [-Wimplicit-function-declaration] (C/C++)implicit declaration …is damaged and can’t be opened — macOS: “App” is damaged and can’t be opened. You should move it to the Trash. (macOS)is damaged and can’t …NO_PUBKEY — The following signatures couldn't be verified because the public key is not available: NO_PUBKEY (Linux)NO_PUBKEYgets

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.