I tried this example:
/* itoa example */
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
char buffer [33];
printf ("Enter a number: ");
scanf ("%d",&i);
itoa (i,buffer,10);
printf ("decimal: %s\n",buffer);
itoa (i,buffer,16);
printf ("hexadecimal: %s\n",buffer);
itoa (i,buffer,2);
printf ("binary: %s\n",buffer);
return 0;
}
but the example there doesn’t work (it says the function itoa doesn’t exist).
Use
sprintf():All numbers that are representable by
intwill fit in a 12-char-array without overflow, unless your compiler is somehow using more than 32-bits forint. When using numbers with greater bitsize, e.g.longwith most 64-bit compilers, you need to increase the array size—at least 21 characters for 64-bit types.