标签:
1 #include <iostream> 2 using namespace std; 3 char *my_reverse(char* s) 4 { 5 char *p,*q; 6 p=s;q=s; 7 while(*q!=‘\0‘) 8 q++; 9 q--; 10 char temp; 11 while(q>=p) 12 { 13 temp=*q; 14 *q--=*p; 15 *p++=temp; 16 } 17 return s; 18 } 19 char* my_itoa(int num) 20 { 21 static char s[100]; 22 int i=0; 23 int isNegative=num; 24 if(isNegative<0) 25 num*=-1; 26 while(num) 27 { 28 s[i]=num%10+‘0‘; 29 num/=10; 30 i++; 31 } 32 if(isNegative<0) 33 s[i++]=‘-‘; 34 s[i]=‘\0‘; 35 return my_reverse(s); 36 } 37 int main() 38 { 39 int num=123; 40 cout<<my_itoa(num)<<endl; 41 system("pause"); 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/riden/p/4663798.html