C语言中使用'atoi'函数时出现警告提示

43

我目前正在编写一本书中的挑战问题的代码。我的代码执行完美,并输出正确的结果,但是我在我的代码中收到了一个警告信息,我想知道为什么。

我在以下这行代码上收到了警告:

int countdownStart = atoi(numInput);

我遇到的警告是:
隐式声明函数'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;
}
1个回答

119

你需要包含stdlib.h头文件

#include <stdlib.h>

下次如果你遇到类似的警告,只需运行man atoi,手册页面会指出应该包含哪个头文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接