catoi

implicit declaration of function ‘atoi’?


Why am I getting an error when using the atoi() function?

#include <stdio.h>
#include <string.h>
int main()
{
    char s1[10], s2[10];
    int x=5, y=6, z;
    sprintf(s1, "%d", x);
    sprintf(s2, "%d", y);
    strcat(s1, s2);
    z = atoi(s1);
    printf("%d, %s", z, s1);
    return 0;
}

Solution

  • #include <stdlib.h>
    

    Will fix it.