C语言 在 C 中收到“atoi”函数的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20778903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting warning in C for 'atoi' function
提问by user3249
I'm currently coding for a challenge question in a book I'm reading. My code executes perfectly with the correct output, but i"m getting a warning in my code and I'm just wondering why.
我目前正在为我正在阅读的书中的一个挑战问题编写代码。我的代码以正确的输出完美执行,但我在我的代码中收到警告,我只是想知道为什么。
I'm getting a warning on the line that reads:
我收到一条警告,内容如下:
int countdownStart = atoi(numInput);
The warning I'm getting says:
我收到的警告说:
Implicit declaration of function 'atoi' is invalid in C99
函数“atoi”的隐式声明在 C99 中无效
#import <readline/readline.h>
#import <stdio.h>
int main(int argc, const char * argv[]){
printf("Who is cool? ");
const char *name = readline(NULL);
printf("%s is cool!\n\n", name);
printf("What should I start counting? ");
const char *numInput = readline(NULL);
int countdownStart = atoi(numInput);
for (int i = countdownStart; i >= 0; i--){
if (i % 3 == 0){
printf("%d\n", i);
if (i % 5 == 0){
printf("Found one!\n");
}
}
}
return 0;
}
回答by Cedric Morent
You have to include stdlib.h
你必须包括 stdlib.h
#include <stdlib.h>
Next time you encounter similar warnings just run man atoiand the manual pages should state that which header file should be included.
下次遇到类似警告时,只需运行man atoi,手册页应说明应包含哪个头文件。

