You must have #include
when you call any function declared in that header.
Ok, that's not quite true. In the 1989/1990 version of the language standard, a call can create an implicit declaration of a function. If that happens to match the correct declaration, you can get away with it;. Otherwise your program's behavior is undefined -- which means you still might get away with it, or not, but the compiler isn't required to warn you about it. Since printf
takes a variable number of arguments, you must have a visible declaration to avoid undefined behavior -- and the way to get a visible declaration is #include
.
(You can also declare the function yourself, but that's error-prone, and there's no good reason to do that.)
In C99 and later, there are no implicit declarations.
main()
should be int main(void)
.
fflush(stdin)
has undefined behavior. If you want to discard characters entered after the scanf()
call, you can read and discard them.