#include <stdio.h>
#define BUFF_SIZE 1024
int int2string(int value, char *buff);
int main(int argc, const char *argv[])
{
int value = -98765432;
char buff[BUFF_SIZE];
int2string(value, buff);
puts(buff);
return 0;
}
int int2string(int value, char *buff)
{
char *h = buff;
char *t = buff;
char tmp;
int flag = 0;
if (value < 0) {
flag = 1;
value = -value;
}
do {
*t = value % 10 + '0';
// printf("value %% 10 = %d\n",value % 10);
// printf("'0' = %c\n",'0');
// printf("*t = %c\n",*t);
value /= 10;
t++;
}while (value != 0);
if (flag)
*t++ = '-';
*t = '\0';
t--;
while (h < t) {
tmp = *h;
*h = *t;
*t = tmp;
h++;
t--;
}
return 0;
}
int类型转换成字符串类型
最新推荐文章于 2023-12-01 23:19:47 发布