atoi实现
来源:互联网 发布:秀图软件 编辑:程序博客网 时间:2024/06/06 16:39
- atoi()函数的功能:将字符串转换成整型数;atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负号才开始做转换,而再遇到非数字或字符串时('\0')才结束转化,并将结果返回(返回转换后的整型数)。
- /*
- * file_name:my_atoi.c
- * function:int my_atoi(char* pstr)
- */
- int my_atoi(char* pstr)
- {
- int Ret_Integer = 0;
- int Integer_sign = 1;
- /*
- * 判断指针是否为空
- */
- if(pstr == NULL)
- {
- printf("Pointer is NULL\n");
- return 0;
- }
- /*
- * 跳过前面的空格字符
- */
- while(isspace(*pstr) == 0)
- {
- pstr++;
- }
- /*
- * 判断正负号
- * 如果是正号,指针指向下一个字符
- * 如果是符号,把符号标记为Integer_sign置-1,然后再把指针指向下一个字符
- */
- if(*pstr == '-')
- {
- Integer_sign = -1;
- }
- if(*pstr == '-' || *pstr == '+')
- {
- pstr++;
- }
- /*
- * 把数字字符串逐个转换成整数,并把最后转换好的整数赋给Ret_Integer
- */
- while(*pstr >= '0' && *pstr <= '9')
- {
- Ret_Integer = Ret_Integer * 10 + *pstr - '0';
- pstr++;
- }
- Ret_Integer = Integer_sign * Ret_Integer;
- return Ret_Integer;
- }
0 0
- LeetCode(atoi)实现atoi
- atoi实现
- atoi实现
- atoi 实现
- 实现atoi
- atoi实现
- 实现atoi
- atoi实现
- atoi实现
- atoi实现
- atoi实现
- atoi实现
- 自己实现atoi系列(atoi函数)
- atoi及itoa 实现
- atoi函数实现
- atoi,itoa函数实现
- 自己实现atoi系列
- atoi,itoa实现
- javascript中expression的用法
- C++ 类型转换归纳
- About@fant-face
- 指针高级运算总结
- nagios插件之监控RTTI返回情况(模拟坐席发起)
- atoi实现
- 为代码生,为代码死,为Debug奋斗一辈子!
- WIN7网关问题问题“在释放接口 Loopback Pseudo-Interface 1 时出错: 系统找不到指定的文件。操作失败,没有适配器处于允许此操作的状态”解决方案
- 4、tracker的三个任务函数之一tracker_mem_check_alive
- HDOJ 1043 Longest Common Substring
- python super类的使用
- linux c编程小结
- Spring Controller 选项
- HDOJ 1159 Common Subsequence