青椒一层层花都黄了是为啥?# gardening - 拈花惹草
w*x
1 楼
const char* myitoa(int num, char str[])
{
assert(a);
char* pIterBeg = str;
if (num < 0)
{
num = -num;
*pIterBeg++ = '-';
}
//use long not short to avoid INT_MIN overflow
unsigned int numshort = num;
char* pIter = pIterBeg;
while (true)
{
*pIter++ = numshort%10 + '0';
numshort = numshort/10;
if (numshort == 0) break;
}
*pIter = 0;
int nLen = strlen(pIterBeg);
assert(nLen > 0);
char* pIterEnd = pIterBeg + nLen - 1;
while (pIterEnd > pIterBeg)
swap(*pIterBeg++, *pIterEnd--);
return str;
}
///////////////////////////////////////////////////////////
一次写对一个itoa真的好难!!! 一点都不简单, atoi更难.
{
assert(a);
char* pIterBeg = str;
if (num < 0)
{
num = -num;
*pIterBeg++ = '-';
}
//use long not short to avoid INT_MIN overflow
unsigned int numshort = num;
char* pIter = pIterBeg;
while (true)
{
*pIter++ = numshort%10 + '0';
numshort = numshort/10;
if (numshort == 0) break;
}
*pIter = 0;
int nLen = strlen(pIterBeg);
assert(nLen > 0);
char* pIterEnd = pIterBeg + nLen - 1;
while (pIterEnd > pIterBeg)
swap(*pIterBeg++, *pIterEnd--);
return str;
}
///////////////////////////////////////////////////////////
一次写对一个itoa真的好难!!! 一点都不简单, atoi更难.