itoa与atoi源代码
2013-07-10 17:05
183 查看
int Myatoi( char* str ) { if (str == NULL) { printf("Invalid Input!\n"); return -1; } while ( (*str)==' ') { str++; } int nSign = (*str=='-')?-1:1; if( *str=='+'|| *str=='-') { *str++; } int nResult = 0; while( *str>='0' && *str<='9') { nResult = nResult*10 + (*str - '0'); *str++; } return nResult*nSign; } char* Myitoa(int num) { char str[1024]; int sign=num, i=0, j=0; char temp[11]; if (sign<0) { num = -num; } do { temp[i] = num%10 + '0'; num /= 10; i++; }while (num>0); if (sign<0) { temp[i++] = '-'; } temp[i]='\0'; i--; while (i>=0) { str[j] = temp[i]; j++; i--; } str[j] = '\0'; return str; } int main() { printf("%d\n",Myatoi("123")); printf("%s\n",Myitoa(-234)); return 0; }itoa与atoi源代码
相关文章推荐
- C函数atoi,itoa的实现代码
- itoa
- itoa与atoi的实现
- itoa与sprintf实现类型转换
- 用itoa()函数将整数转换为字符串
- 将数字n转换为字符串的函数itoa
- poj 1546 好用的strtol和itoa
- itoa使用
- 自己实现itoa(),10进制到2~36进制的转换
- itoa 原函数
- 微软面试20 itoa的实现
- 对C++的atoi(),substr(),c_str(),itoa()函数的理解
- C++ 类型转换 atoi atol atof <stdlib.h>, itoa ftoa char <---> string
- 常用的函数:atoi,itoa,atof,_ttoi等
- itoa
- c语言中函数itoa的解释及作用
- 【C】——itoa 函数的实现
- c itoa和atoi
- C++ - "'itoa' was not declared in this scope" 错误
- c++实现atoi()和itoa()函数(字符串和整数转化)