atoi与itoa代码实现
2014-12-04 15:27
260 查看
#include<iostream> #include<stdio.h> using namespace std; void main() { int num=-12345,j=0,i=0; char temp[7],str[7]; if(num<0) { temp[i]='-'; i++; } num=abs(num); while(num) { temp[i]=num%10+'0'; i++; num/=10; } temp[i]=0; i--; if(temp[0]=='-') { str[j++]=temp[0]; while(i>0) { str[j]=temp[i]; j++; i--; } } else { while(i>=0) { str[j]=temp[i]; j++; i--; } } str[j]=0; cout<<str<<endl; int numb=-34567; char strs[7]; itoa(numb,strs,10); cout<<strs<<endl; /*---------------atoi--------------*/ char *ch="123456";//不包含负数情况 int chi=0,tempnum=0; while(chi<strlen(ch)) { tempnum=tempnum*10+ ch[chi++]-'0'; } cout<<"tempnum="<<tempnum<<endl; int sumtemp=0; cout<<"atoi="<<atoi(ch)<<endl; system("pause"); }
相关文章推荐
- itoa与atoi的实现
- atoi 与 itoa的实现
- atoi 与 itoa的详解和实现源代码
- C语言实现atoi,itoa和atof
- atoi和itoa的实现
- atoi() & itoa()函数的内部的实现
- 基础函数的实现(strcpy,strcat, strcmp, atoi, itoa)
- itoa与atoi的实现
- 实现atoi,itoa,strcmp,strcpy,strcat,strlen函数
- 基础函数的实现(strcpy,strcat, strcmp, atoi, itoa)
- atoi 与 itoa的实现
- atoi() & itoa()函数的内部的实现
- atoi,itoa实现
- 源码:微软strcpy,strcat和strcmp的实现源代码 itoa atoi
- itoa与atoi ftoa与atof的实现
- atoi和itoa的实现
- atoi() & itoa()函数的内部的实现
- atoi() itoa() 的实现
- itoa atoi ltoa ultoa函数原型实现
- atoi和itoa的C实现