gpt4 book ai didi

c - 在 C 中获取 'atoi' 函数的警告

转载 作者:太空狗 更新时间:2023-10-29 16:23:12 26 4
gpt4 key购买 nike

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

我在行中收到警告:

int countdownStart = atoi(numInput);

我收到的警告是:

Implicit declaration of function 'atoi' is invalid in 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;
}

最佳答案

你必须包含 stdlib.h

#include <stdlib.h>

下次您遇到类似的警告时,只需运行 man atoi 并且手册页应该说明应该包含哪个头文件。

关于c - 在 C 中获取 'atoi' 函数的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20778903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com