Fix “too few arguments to function” in C
Every C call site must supply the exact parameter count declared by the visible function signature (unless the signature ends with variadic `...` like `printf`). Omitting trailing stream or length arguments—or calling `int f(void)` with arguments—stops compilation.
Quick Fix Summary
Check the header signature (man 3 fgets or IDE hover), supply all required buffer-size and stream parameters, and write int func(void) rather than int func() when a C17 function accepts zero arguments.
Why This Error Happens
Replacing 1-argument gets(buf) with 3-argument fgets
Removed gets(buf) took one argument, whereas safe fgets(buf, sizeof buf, stdin) requires buffer pointer, byte capacity, and FILE * stream.
Empty parentheses f() in C17 vs C23
In C17, int f(); meant unspecified parameters (allowing accidental extra arguments without checking), whereas in C23 int f(); means (void) and rejects extra arguments immediately.
Top Root Causes & Specific Code Fixes
Calling fgets(line) with 1 or 2 arguments instead of 3
fgets always requires destination buffer, max byte length, and input FILE stream.
char line[64];
fgets(line, sizeof line);char line[64];
fgets(line, sizeof line, stdin);Misplaced closing parenthesis ending a call early
Closing `fopen("data.txt"), "r"` after the first argument leaves `"r"` outside the call.
FILE *fp = fopen("data.txt"), "r";FILE *fp = fopen("data.txt", "r");Complete Broken and Corrected Programs
Compare the source before running it. The broken program is intentionally incorrect; its behavior can depend on the compiler and platform.
Read the broken program
#include <stdio.h>
int add_pair(int a, int b) {
return a + b;
}
int main(void) {
printf("%d\n", add_pair(10));
return 0;
}Open broken program in compilerRead the corrected program
#include <stdio.h>
int add_pair(int a, int b) {
return a + b;
}
int main(void) {
printf("%d\n", add_pair(10, 25));
return 0;
}Open corrected program in compilerExpected output from the corrected program
Reference output, not a live execution result.
35Debugging Techniques and Commands
gcc -std=c17 -Wall -Wextra -Wstrict-prototypes main.c -o app
Catches old K&R `int fn()` declarations missing `(void)`.
Read the compiler `note: declared here` line immediately below the error.
Shows the exact header line and expected parameter list.
Frequently Asked Questions
Does C support default parameter values like int fn(int a, int b = 0)?
No. ISO C does not have default arguments or function overloading; define a helper wrapper function with a distinct name if a shorthand call is needed.
Why does printf accept different numbers of arguments?
`printf` is declared variadic (`const char * restrict format, ...`), using the format string to determine trailing arguments.
What does int main(void) vs int main() mean in C17?
In C17, `int main(void)` explicitly declares zero parameters; `int main()` leaves parameter checking unspecified until C23.