简体   繁体   中英

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

#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

#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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM