[英]Getting warning in C for 'atoi' function
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;
}
You have to include stdlib.h 您必须包含stdlib.h
#include <stdlib.h>
Next time you encounter similar warnings just run man atoi
and the manual pages should state that which header file should be included. 下次您遇到类似的警告时,只需运行man atoi
,手册页应说明应包含哪个头文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.