整型转字符串itoa
itoa代码的实现
#include
#include
value整型 以 radix 进制 做转换,转换结果保存到buffer数组
char* my_itoa(int value, char* arr, int radix)
{
assert(value != 0);
char index[] = { "0123456789ABCDEF" };
int flag = value < 0 && radix == 10 ? 1 : 0;
if (flag == 0)
{
arr[0] = '-';
value * -1;
}
unsigned int value_temp = (unsigned int)value;
int i= flag;
for (; value_temp != 0; i++)
{
arr[i] = index[value_temp % radix];
value_temp = value_temp / radix;
}
arr[i] = '
整型转字符串itoa最先出现在Python成神之路。
共有 0 条评论