C语言int变成string
C语言怎么把int变成string,不能用itoa()函数,如22变成"22" #include <stdio.h>void Swap(char *a, char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
char *NumberToString(char *buf, size_t number)
{
char *p = buf;
while(number)
{
int remainder = number % 10;
number /= 10;
*p++ = '0' + remainder;
}
*p = '\0';
char *q = p;
p = buf;
while(p < q)
Swap(p++, --q);
return buf;
}
int main(void)
{
char buf;
puts(NumberToString(buf, 1234567));
return 0;
}
to_string(22)
页:
[1]