Search code examples
citoa

C Error: undefined reference to '_itoa'


I'm trying to convert an integer to a character to write to a file, using this line:

fputc(itoa(size, tempBuffer, 10), saveFile);

and I receive this warning and message:

warning: implicit declaration of 'itoa'

undefined reference to '_itoa'

I've already included stdlib.h, and am compiling with:

gcc -Wall -pedantic -ansi

Any help would be appreciated, thank you.


Solution

  • itoa is not part of the standard. I suspect either -ansi is preventing you from using it, or it's not available at all.

    I would suggest using sprintf()

    If you go with the c99 standard, you can use snprintf() which is of course safer.

    char buffer[12];
    int i = 20;
    snprintf(buffer, 12,"%d",i);