||
const char *CharTable="0123456789";
char ltoa(long ulValue,char *strBuf)
{
unsigned long index,NegFlag;
char PosNo;
if(ulValue<0)
{
NegFlag=1;
PosNo=1;
strBuf[0]='-';
ulValue= -ulValue;
}
else
{
NegFlag=0;
PosNo=0;
}
for(index=1; index*10 <=ulValue ; index*=10)
;
for(;index;index/=10)
{
strBuf[PosNo++]=CharTable[(ulValue/index)%10];
}
strBuf[PosNo]='\0';
return PosNo;
}
返回值为有效字符数(不包括结束符'\0').