void IntToStr(int a,char* str){
if(a==0){
*str='0';
*(str+1)='\0';
return;
}
char* p = str;
if(a<0){
a=a*(-1);
*p++ = '-';
}
int len = 0;
while(a){
*p++ = a%10+'0';
a/=10;
++len;
}
int start = *str=='-'?1:0;
int tmp;
for(int i=0;i<len/2;++i){
tmp = str[start+i];
str[start+i]=str[len+start-1-i];
str[len+start-1-i]=tmp;
}
str[len+start]='\0';
}
void main(){
char* str = new char[12];
//IntToStr(0,str);
IntToStr(-12340,str);
//IntToStr(214748367,str);
printf("%s\n",str);
}
posted on 2009-09-26 15:41
iConnect 阅读(181)
评论(0) 编辑 收藏 所属分类:
数学&算法&数据结构