Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting warning in C for 'atoi' function

Tags:

c

xcode

atoi

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; } 
like image 949
user3249 Avatar asked Dec 26 '13 03:12

user3249


1 Answers

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.

like image 177
Cedric Morent Avatar answered Sep 18 '22 14:09

Cedric Morent