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.
C Programming/stdlib. h/itoa The itoa (integer to ASCII) function is a widespread non-standard extension to the standard C programming language. It cannot be portably used, as it is not defined in any of the C language standards; however, compilers often provide it through the header <stdlib.
When the radix is DECIMAL, itoa() produces the same result as the following statement: (void) sprintf(buffer, "%d", n); with buffer the returned character string. When the radix is OCTAL, itoa() formats integer n into an unsigned octal constant.
itoa() is not ANSI-C defined and it not part of C++, and C32 is GCC based, and it is not really supported in GCC.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With