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.
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);
This here tells you that during the compilation phase itoa
is unknown:
warning: implicit declaration of 'itoa'
so if this function is present on your system you are missing a header file that declares it. The compiler then supposes that it is a function that takes an unspecific number of arguments and returns an int
.
This message from the loader phase
undefined reference to '_itoa'
explains that also the loader doesn't find such a function in any of the libraries he knows of.
So you should perhaps follow Brian's advice to replace itoa
by a standard function.
来源:https://stackoverflow.com/questions/5428632/c-error-undefined-reference-to-itoa