atol(atoi)函数的实现要点
来源:互联网 发布:大闹天宫玉玺4进5数据 编辑:程序博客网 时间:2024/05/21 18:34
以下是c标准库中该函数的实现代码,从中分析要点
- /***
- *atox.c - atoi and atol conversion
- *
- * Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
- *
- *Purpose:
- * Converts a character string into an int or long.
- *
- *******************************************************************************/
- /***
- *long atol(char *nptr) - Convert string to long
- *
- *Purpose:
- * Converts ASCII string pointed to by nptr to binary.
- * Overflow is not detected.
- *
- *Entry:
- * nptr = ptr to string to convert
- *
- *Exit:
- * return long int value of the string
- *
- *Exceptions:
- * None - overflow is not detected.
- *
- *******************************************************************************/
- long __cdecl atol(
- const char *nptr
- ) //1.const修饰
- {
- int c; /* current char */
- long total; /* current total */
- int sign; /* if ''-'', then negative, otherwise positive */
- /* skip whitespace */
- //char ,signed char 、unsigned char 类型的数据具有相同的特性然而当你把一个单字节的数赋给一个整型数时,便会看到它们在符号扩展上的差异。
- //ascii码当赋给整形数时要转为unsigned char再转为int
- while ( isspace((int)(unsigned char)*nptr) ) //2.去掉首部的空格
- ++nptr;
- c = (int)(unsigned char)*nptr++; //取得第一个非空格的字符
- sign = c; /* save sign indication */
- if (c == '-' || c == '+') //如果第一个非空格字符为符号
- c = (int)(unsigned char)*nptr++; /* skip sign */ //跳过符号,将符号后的那个字符给c
- total = 0; //结果置为0
- while (isdigit(c)) { //3.如果碰到非法字符则停止
- total = 10 * total + (c - '0'); /* accumulate digit */
- c = (int)(unsigned char)*nptr++; /* get next char */
- }
- if (sign == '-')
- return -total;
- else
- return total; /* return result, negated if necessary */
- }
- atol(atoi)函数的实现要点
- atol(atoi)函数的实现要点
- atoi atol实现
- 数据类型转换函数strtod | atoi | atol
- 函数atof,atoi,atol,strtod,strtol,strtoul
- atoi,itoi,atol,strtol, strtod函数转换
- atoi,atol,strtol等几个转换函数
- atoi(), atol(), itoa(), sprintf() 及 strcat()函数
- 函数atof,atoi,atol,strtod,strtol,strtoul
- c字符串转换函数atoi、atof、atol
- atoi atof atol等系列函数
- atol函数简单实现
- itoa()和atoi()/atol()的源码
- atoi函数的实现
- atoi()函数的实现
- atoi()函数的实现
- atoi函数的实现
- atoi函数的实现
- java开发基本知识
- Java新手 运行求质因子for循环有问题,但是我找不到错误,谁能帮我解决,谢谢,在线等
- DotNetNuke 5 C#版本解读之1--架构介绍
- install taverna server + emboss + soaplab2
- JAVA 从键盘读取字符并且转换成数字
- atol(atoi)函数的实现要点
- Linux开机自动挂载Windows分区的两种方法
- WindowsXP Kernel32.dll中的函数
- 【socket】socket 工作流程
- 集合类
- Java Servlet技术
- Android Intent的几种用法全面总结
- CRF&HMM的Matlab代码
- 什么时候java中 用final