itoa standart olarak c/c++ lib'lerinde yok diye biliyorum ben? yanlis olabilir tabi bu bilgim..
itoa ihtiyacim 1 kez oldu (o da psp icin), onda da snprintf kullandim..
//code: gfoot
char *itoa (int num, char *str, int base)
{
char *pos = str;
int digit_value;
if (num < 0) {
*pos++ = '-';
num = -num;
}
digit_value = 1;
while (digit_value*base <= num) digit_value *= base;
while (digit_value > 0) {
int digit = num / digit_value;
num -= digit * digit_value;
*pos++ = '0' + digit;
digit_value /= base;
}
*pos = '\0';
return str;
}
EDIT:
[FONT=Courier New]sprintf()[/FONT] is the easiest way to do this in most cases. It may seem odd that [FONT=Comic Sans MS]itoa()[/FONT] is not standard when [FONT=Courier New]atoi()[/FONT] is, but apparently the standards committee felt that the former wasn't as portable as the latter (at least I seem to recall that being part of the reason). Also, whereas [FONT=Courier New]atoi()[/FONT] can return an integer value as a function, [FONT=Courier New]itoa()[/FONT] would need to either take a char buffer to write the values into (as the usual version does), or else allocate a string dynamically and return that (which goes against the general design principles of the standard library, which usually avoids dynamic allocation wherever possible).