C语言中的itoa和atoi函数的实现
itoa与atoi的代码实现:
int atoi(char *str) {char *p=str;switch(*p){case '+':p++;break;case '-':p++;break;default:break;}if(!(*p>='0' && *p<='9')){printf("format error"); return 0;}int result = 0; for(;*p!='\0';p++){if(*p>='0' && *p<='9')result=result*10+ (*p-'0');else {printf("format error");return 0;} }if(*str == '-')result = -result;return result; }void itoa(int number,char *str) {char ch[100],*p=str;int sign=1,i;if(number<0){sign=-1;number=-number;}for(i=0;number!=0;number/=10,i++){ch[i]=number%10 + '0';}if(sign==-1)*p='-';i--;for(;i>=0;i--,p++)*p=ch[i];*p='\0'; }
C语言中的itoa和atoi函数的实现相关推荐
- 转:(记录)C语言中的itoa()函数的用法解析
本博客转自文章:https://www.cnblogs.com/bluestorm/p/3168719.html C语言中的 itoa() 函数的用法: C语言提供了几个标准库函数,可以将任意类型 ( ...
- c语言 strcpy原型,浅谈C语言中strcpy,strcmp,strlen,strcat函数原型
实例如下: //strcat(dest,src)把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0' char *strcat(char * strDest, cons ...
- C语言中的rename()和remove()函数的使用及注意点
C语言中的rename()和remove()函数的使用及注意点 C语言中rename() 和remove()函数属于文件处理函数,其中rename() 对文件或目录进行移动和删除. int ret = ...
- C语言中的malloc与free函数
C语言中的malloc与free函数 malloc函数的作用是在堆中开辟一块指定大小的空间.如果开辟成功,返回空间首个字节地址,失败则返回NULL. free函数能够释放在堆中开辟的内存空间,传入一个 ...
- C语言中itoa和atoi函数的用法
1.itoa函数的用法 (1) 函数说明 itoa是广泛应用的非标准C语言扩展函数.由于它不是标准C语言函数,所以不能在所有的编译器中使用.但是,大多数的编译器(如Windows上 的)通常在< ...
- 关于C语言中的malloc和free函数的用法
一.malloc()和free()的基本概念以及基本用法: 1.函数原型及说明: void *malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针 ...
- c++freopen函数_使用示例的C语言中的freopen()函数
c++freopen函数 C语言中的freopen()函数 (freopen() function in C) Prototype: 原型: FILE* freopen(const char *str ...
- putc函数_C语言中的putc()函数与示例
putc函数 C语言中的putc()函数 (putc() function in C) The putc() function is defined in the <stdio.h> he ...
- c语言中的printf函数_C语言中的printf()函数与示例
c语言中的printf函数 C语言中的printf()函数 (printf() function in C) The printf() function is defined in the <s ...
最新文章
- python爬虫 发送定时气象预报
- slf4j 使用方法---个人总结
- android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProcessor'
- 社交电商风潮起,中小卖家何处去
- 【转】LDA数学八卦
- 微课|中学生可以这样学Python(例7.2):三维向量类
- 实现裸金属服务器的安全微分段
- python机器学习库sklearn——BIRCH聚类
- mysql 查询结果导出文件并导入文件到数据库
- BC26常用术语和缩略词
- RNA 6. 差异基因表达之-- 火山图 (volcano)
- Linux服务器建立IP隧道,变更访问出口
- VLIW Microprocessor Hardware Design
- 基于VUMAT复合材料夹层结构冲击仿真
- 十六国帝王纪元表-20170722
- vs2010环境下wincap的配置
- 数仓(六)从0到1简单搭建数仓ODS层(埋点日志 + 业务数据)
- php计算两个地点的距离
- java中的\uxxxx
- C++:重定义:符号重定义:变量重定义(二):解决变量重定义(const static)