zoukankan      html  css  js  c++  java
  • C语言函:atoi

    atoi
    atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数,应用在计算机程序和办公软件中。int atoi(const char *nptr) 函数会扫描参数 nptr字符串,会跳过前面的空白字符(例如空格,tab缩进)等。如果 nptr不能转换成 int 或者 nptr为空字符串,那么将返回 0 [1] 。特别注意,该函数要求被转换的字符串是按十进制数理解的。atoi输入的字符串对应数字存在大小限制(与int类型大小有关),若其过大可能报错-1。
    外文名atoi参 数字符串返回值int适用语言C/C++头文件#include <stdlib.h>

    C语言库函数名:atoi
    原型:int atoi(const char *nptr);
    UNICODE:_wtoi()

    //vs2013里调用printf函数请使用预处理命令#define _CRT_SECURE_NO_WARNINGS
    #include <stdlib.h>
    #include <stdio.h>
     
    int main(void)
    {
        int n;
        char *str = "12345.67";
        n = atoi(str);
        printf("n=%d
    ",n);
        return 0;
    }
    输出:
    n = 12345
    
    //vs2013里调用printf函数请使用预处理命令#define _CRT_SECURE_NO_WARNINGS
    #include <stdlib.h>
    #include <stdio.h>
     
    int main()
    {
        char a[] = "-100";
        char b[] = "123";
        int c;
        c = atoi(a) + atoi(b);
        printf("c=%d
    ", c);
        return 0;
    }
    执行结果:
    c = 23
    
  • 相关阅读:
    重塑矩阵
    买卖股票
    两个数组的交集
    洛谷 P3700
    HDU 6987
    Solution -「NOI 2021」「洛谷 P7740」机器人游戏
    「NOI 2021」酱油记
    Solution -「UNR #5」「UOJ #671」诡异操作
    CD from Codeforces Round #703 (Div. 2)
    CD from Codeforces Round #701 (Div. 2)
  • 原文地址:https://www.cnblogs.com/yzmy/p/14194961.html
Copyright © 2011-2022 走看看