warning: format '%s' expects argument of type 'char *', but argument has type 'char (*)[10]' / scanf overflows buffer

scanf was called with a wrong format/argument combination or without a width limit.

Exact message you may see scanf buffer overflowscanf missing & segmentation faultformat '%s' expects argument of type 'char *'ignoring return value of scanf
Seen on: C GCC

Meaning

%s stops only at whitespace and writes past the buffer. %d needs int*, %f needs float* and %lf needs double*. Forgetting & for numbers gives a crash.

Common causes

  • Missing & before a numeric variable
  • %f used for double (needs %lf)
  • %s without width
  • Return value of scanf ignored

⚡ Quick fix

  1. Use scanf("%9s", buf) with a width one less than the buffer
  2. Check the return value (== 1)
  3. Prefer fgets + strtol

Detailed fix by platform

C

  1. if (scanf("%d", &n) != 1) { /* handle bad input */ }

Code examples

Safe scanf

c
int n; char name[10];
scanf("%d", n);        // crash: missing &
scanf("%s", name);     // overflow if input is longer than 9 chars
scanf("%d", &n);
scanf("%9s", name);

How to diagnose

  1. Types — Format matches argument?
  2. Width — Specified?
  3. Return — Checked?

🔧 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):

call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…format expects argument of type — C: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=] (C/C++)format expects argume…gets — implicit declaration of function 'gets' / warning: the `gets' function is dangerous and should not be used (C/C++)getsreference to is ambiguous — C++: error: reference to 'X' is ambiguous (using namespace std conflicts) (C/C++)reference to is ambig…region FLASH overflowed — arm-none-eabi-ld: region `FLASH' overflowed by N bytes (C/C++)region FLASH overflow…Segmentation fault — C/C++: Segmentation fault (core dumped) — SIGSEGV from a null, dangling or out-of-bounds pointer (C/C++)Segmentation faultscanf

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.