implicit declaration of function 'GetInt' is invalid in C99
Though daunting, the compiler makes it very clear - your code implies that you want to use GetInt
, but you instead use get_int()
. I have found that, at times, the compiler and CS50 library can be very sensitive, so it is best to use the regular version, GetInt()
. In the CS50 file, how GetInt
is named/defined - get_int
, Get_Int
, GetInt
, or any variation thereof - can affect how the function performs and how to call on that function.
I created a test program to show you how that works. Here is my test program:
// define function
bool function(int a, int b);
int main(void)
{
// set variables
int x = 0;
int y = 1;
// check if function evaluates to true
if (Function(y, x) == true)
{
printf("True!");
}
}
// checks if a > b
bool function(int a, int b)
{
if (a > b)
{
return true;
}
else
{
return false;
}
}
Since GetInt
is a function, I chose to create a function called function
that tests if int a
is less than int b
. You'll see that in the line if (Function(y, x) == true)
, I test to see if the function returns true. However, I use a different spelling - Function
instead of function
. This returns the same error that you get on your program:
something.c:13:9: error: implicit declaration of function 'Function' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (Function(y, x) == true)
When I change Function
to function
, the original spelling I define my function as, I can compile just fine without any errors. I hope that my example can explain why get_int
might be considered invalid - and show you why you might get that error in the future.
int x = get_int()
worked for me in another program I created, but I have seen from other answers that CS50 is case-sensitive. However, get_int
should work, and if it doesn't, you might want to consider re-saving, re-compiling, and refreshing your file. However, if you want to go the "easy" route, you can change get_int()
to GetInt()
.
If this answers your question, please click the green checkmark! Comment below if you still have issues/questions.
int x = get_int();
in a test program I made and there is no compilation error. I suggest refreshing, resaving, and re-compiling the file. If you are still getting errors, you might consider usingGetInt()
instead and see if that works.