模拟itoa
来源:互联网 发布:jieba 词性标注 java 编辑:程序博客网 时间:2024/06/06 19:43
char* itoa(int num, char*str, int radix){/*索引表*/char index[] = "0123456789ABCDEF";unsigned unum;/*中间变量*/int i = 0, j, k;/*确定unum的值*/if (radix == 10 && num<0)/*十进制负数*/{unum = (unsigned)-num;str[i++] = '-';}else unum = (unsigned)num;/*其他情况*//*转换*/do{str[i++] = index[unum % (unsigned)radix];unum /= radix;} while (unum);str[i] = '\0';/*逆序*/if (str[0] == '-')k = 1;/*十进制负数*/else k = 0;char temp;/*for (j = k; j <= (i - 1) / 2; j++){temp = str[j];str[j] = str[i - 1 + k - j];str[i - 1 + k - j] = temp;}*/ j = i-1;while (k <= j){swap(str[k],str[j]);k++;j--;}return str;}int main(){char str[50];printf("%s", itoa(1233, str, 10));system("pause");}
0 0
- 模拟itoa
- 模拟实现atoi、itoa
- 模拟itoa和atoi
- 【字符串】模拟实现atoi和itoa
- 模拟c库函数atoi和itoa
- 模拟实现atoi和itoa函数
- 模拟C库中atoi与itoa
- 模拟实现memcpy,memmove,atoi,itoa
- itoa
- itoa
- itoa
- itoa
- itoa
- itoa
- itoa
- itoa
- itoa
- itoa
- linux 常用命令
- GCC中常用命令
- Java自定义注解
- LeetCode 11. Container With Most Water
- 游戏开发----启程篇
- 模拟itoa
- Android-系统悬浮窗
- 【Android studio】Error:Failed to open zip file. Gradle’s dependency cache may be corrupt
- 开源总结
- Nginx+Tomcat+Redis搭建共享SESSION集群
- Android AutoTest(一):搭建环境 eclipse+Android+appium+Python(win7)
- sqoop1.99.6安装
- 文章 & 教程
- 【脚本语言系列】关于PythonGUI编程wxPython, 你需要知道的事