代码来自陈硕
const char*convert(char buf[], int value) {
static char digits[19] =
{
'9', '8','7','6','5','4','3','2','1','0',
'1','2','3','4','5','6','7','8','9'
};
static const char* zero = digits +9;
int i = value;
char *p = buf;
do {
// lsd - least significant digit
int lsd = i %10;
i /=10;
*p++ = zero[lsd];
}while (i !=0);
if (value <0) {
*p++ ='-';
}
*p ='\0';
reverse(buf, p);
return p;
}
网友评论