ccompiler-errors

implicit declaration of function ‘getChar’ in C


Some I have this error when I try to compile a program in C.

myfunctions.c:27:2: warning: implicit declaration of function ‘getChar’ [-Wimplicit-function-declaration]

Here is line 27:

while(myChar = getChar() && myChar != '')

I'm calling this in the header:

#include <stdio.h>
#include <unistd.h>

Solution

  • It's spelled getchar, not getChar. C is case sensitive, and pretty much all the standard C functions' names are all lowercase.

    As for why it's "implicitly declared" when it doesn't exist...in older versions of C, if a function name isn't known to the compiler, it's assumed to be a function that returns an int. It's almost as if you said int getChar();. I hear C99 doesn't allow this, but most compilers don't stick to it anyway unless you tell them to.