C语言中经常用到字符串与数字之间的相互转换,常见的此类库函数有atof(字符串转换成浮点数)、atoi(字符串转换成整型数)、atol(字符串转换成长整形)、itoa(整型数转换成字符串)、ltoa(长整形转换为字符串)等。

  以下为自定义Myatoi()函数的实现以及测试代码。

 #include <stdio.h>
int Myatoi(char*str){
if (str == NULL){
printf("Invalid Input");
return -;
}
while (*str == ' '){
str++;
}
while ((*str == (char)0xA1) && (*(str + ) == (char)0xA1)){
str += ;
}
int nSign = (*str == '-') ? - : ;//确定符号位
if (*str == '+' || *str == '-'){
str++;
}
int nResult = ;
while (*str >= ''&& *str <= ''){
nResult = nResult * + (*str - '');
str++;
}
return nResult *nSign;
} int main(){
printf("%d\n", Myatoi(""));
return ;
}

笔试面试记录-字符串转换成整型数等(aatoi,itoa)的更多相关文章

  1. 字符串转换成整型数 atoi()

    题目说明: 1.设计函数: int atoi(const char *nptr); 2.功能:把字符串转换成整型数,atoi()会扫描参数nptr字符串,如果第一个非空格字符存在, 是数字或者正负号则 ...

  2. 字符串转换成整型,到底使用int.Parse,Convert.ToInt32还是int.TryParse?

    当我们想把一个字符串转换成整型int的时候,我们可能会想到如下三种方式:int.Parse,Convert.ToInt32和int.TryParse.到底使用哪种方式呢? 先来考虑string的可能性 ...

  3. python将字符串转换成整型

    将字符串转换成,整型,从字面理解很容易让人误会. 比如,要把这个"abcabc"转换成整型,臣妾做不到啊.除成转成ascii. 我们所说字符串转成整型是这样的. s = " ...

  4. 腾讯測试project师笔试面试记录

        从3月29日參加腾讯笔试開始,開始了为期1周的腾讯之旅,尽管最后还是跪在了二面上,可是感觉收获非常多,至少明确了自己与向往的BAT公司的差距,明确了自己还是路漫漫其修远兮.     腾讯非常注 ...

  5. VC++中如何将字符串转换成整型数字

    原文:http://blog.csdn.net/yongf2014/article/details/47071663 注意: atoi函数是c的函数,它的输入参数是char *类型. 你声明了stri ...

  6. 【Linux C中文函数手册】 字符串转换函数

    字符串转换函数 1)atof 将字符串转换成浮点型数 相关函数 atoi,atol,strtod,strtol,strtoul表头文件 #include <stdlib.h>定义函数 do ...

  7. atol字符串转换函数应用实例

    原型:long atol(const char *nptr); 相关函数 atoi,atol,strtod,strtol,strtoul 头文件:stdlib.h 功能:将字符串转换成整型数 说明:参 ...

  8. Linux常用C函数---字符串转换篇

    函数讲解部分参考http://net.pku.edu.cn/~yhf/linux_c/ atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoul 表 ...

  9. 字符串转换atof atoi atol gcvt strtod strtol strto ul toascii tolower toupper

    atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoul 表头文件 #include <stdlib.h> 定义函数 double at ...

随机推荐

  1. tiler--python实现的有趣的自定义马赛克图像拼接工具

    最近在github中发现了一个有趣的小工具,tiler github链接https://github.com/nuno-faria/tiler 具体介绍请直接去github,这里只分享一下它的使用方法 ...

  2. 搭建一个Semantic-ui项目

    一.进入到项目目录 npm init 二.安装semantic-ui npm install semantic-ui --save 三.编译输出semantic-ui cd  ./semantic g ...

  3. Ionic cordova-plugin-splashscreen

    1.添加插件 cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git 2.设置启动画面 在根目录下面r ...

  4. vue.js_02_vue.js的基础指令

    1.v-cloak 作用:解决插值表达式闪烁的问题 当网速过慢时,或者加载数据时间过长时,网页会出现  {{msg}}  的现象 使用方法: <!--缺陷需要写style样式--> < ...

  5. light oj 1037 状压dp

    #include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...

  6. Maven实战05_背景案例学Maven模块化

    1:简单的账户注册服务 注册互联网账户是日常生活中再熟悉不过的一件事,作为一个用户,注册账户的时候需要进行以下操作,提供以下信息. 提供一个未被使用的帐号ID 提供一个未被使用的email地址. 提供 ...

  7. non-identifying and identifying

    An identifying relationship means that the child table cannot be uniquely identified without the par ...

  8. mapreduce join操作

    上次和朋友讨论到mapreduce,join应该发生在map端,理由太想当然到sql里面的执行过程了 wheremap端 join在map之前(笛卡尔积),但实际上网上看了,mapreduce的笛卡尔 ...

  9. Jquery 页面打印

    <script src="~/Scripts/js/dist/jquery.jqprint-0.3.js"></script> <script typ ...

  10. Leetcode200. Number of Islands岛屿的个数

    给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 1: 输入: ...