itoa函数简单实现
2015-03-02 22:29
288 查看
实现itoa函数
<span style="font-size:18px;">#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> void int_str(int n, char* str) { int sign = n, i = 0, j = 0; //sign用来标记,判断输入的n大于或小于0 char temp[10]; n = sign < 0 ? -n : n; do { temp[i] = n % 10 + '0'; n /= 10; i++; } while (n>0); //循环结束i比数组有效字符个数大一 if (sign < 0) { temp[i++] = '-'; } temp[i] = '\0'; i--; while (i >= 0) { str[j++] = temp[i--]; } str[j] = '\0'; } void main() { int n; char str[10]; printf("Please intput integer:"); scanf("%d", &n); int_str(n, str); printf("Output:%s\n", str); system("pause"); }</span>
相关文章推荐
- 简单的实现itoa函数
- atoi函数和itoa函数的简单实现
- 用vb.net与acess结合实现简单的电话号码本程序(一)
- XML 简单接口 (SAX2)用Visual Basic 实现的示例
- 简单实现Crystal Report的动态加载
- 跨域名的Cookie实现---简单另类的实现方法
- 用NUnit2.1简单实现.net的测试驱动开发(TDD)
- 内容分页简单实现代码及祥解(C#)
- Dhtml+Js算法:5个小球运动的简化版,变通实现更简单的飞行的图片
- 打印的简单实现,以及更改打印设置
- Editplus + Zend Encoder实现简单PHP源码加密IDE环境
- 一个简单聊天室的两种实现 (fcntl 和 select)
- http断点续传简单实现(java)
- 自己如何实现简单的http服务器
- 简单的在线升级的实现方法
- 简单分析用SPI实现防火墙
- 初学者看过来:简单谈谈 C/C++ 递归的思想,实现,以及和循环的关系。
- 一个简单的菜单按钮的实现
- Dhtml:用ondrag事件简单的实现鼠标拖动物件.
- Web报表打印·简单实现·(一)