scanf
Formatted input — reads values into variables via pointers.
Easy
int n;
if (scanf("%d", &n) != 1) { /* handle bad input */ }
Check the return value; never use %s without a width (%19s) — buffer overflow. For robust input, read a line with fgets then parse with sscanf/strtol.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.