我正在尝试用C语言编写这个简单的代码,它要求用户给出一个正数,检查它是否是正数,然后只返回正数。
我得到了这个错误:
positive.c:28:7: warning: implicit declaration of function 'GetInt' is invalid
in C99 [-Wimplicit-function-declaration]
n = GetInt();
我会认为这意味着我没有声明我的一个函数,或者我没有调用某个库。据我所知,这一切都是我做的。下面是我的代码:
#include <stdio.h>
int GetPositiveInt(void);
int main(void)
{
int n = GetPositiveInt();
printf("Thanks for the %i\n", n);
}
/*This all gets called into the above bit*/
int GetPositiveInt(void)
{
int n; /*declare the variable*/
do
{
printf("Give me a positive integer: ");
n = GetInt();
}
while (n <= 0);
return n; /*return variable to above*/
}
有人知道为什么这会给我一个错误吗?
https://stackoverflow.com/questions/19288370
复制相似问题