zoukankan      html  css  js  c++  java
  • strtol简介

    strtol简介

    long int strtol(const char *nptr char **endptr int base)

    strtol()会将nptr指向的字符串,根据参数base,按权转化为long int 然后返回这个值。

    参数base的范围为2~36和0;它决定了字符串以被转换为整数的权值。

    可以被转换的合法字符依据base而定,举例来说,当base2时,合法字符为‘0’‘1’base8时,合法字符为‘0’‘1’……‘7’base10时,合法字符为‘0’‘1’……‘9’base 16时,合法字符为‘0’‘1’……‘9’‘a’……‘f’base24时,合法字符为‘0’……‘9’‘a’……‘n’base36时,合法字符为‘0’……‘9’‘a’……‘z’;等等。其中,不区分大小写,比如,‘A’‘a’会都会被转化为10

    当字符合法时,‘0’……‘9’依次被转换为十进制的09‘a’……‘z’依次转换为十进制的1035

    strtol()函数检测到第一个非法字符时,立即停止检测,其后的所有字符都会被当作非法字符处理。合法字符串会被转换为long int作为函数的返回值。非法字符串,即从第一个非法字符的地址,被赋给*endptr**endptr是个双重指针,即指针的指针。strtol()函数就是通过它改变*endptr的值,即把第一个非法字符的地址传给endptr

    多数情况下,endptr设置为NULL 即不返回非法字符串。

    示例

    ------------------------------------------------------

    char buffer[20]="10379cend$3";

    char *stop;

    printf("%d\n",strtol(buffer, &stop, 2));

    printf("%s\n", stop);

    输出结果:

    2

    379cend$3

    -------------------------------------------------------

    char buffer[20]="10379cend$3";

    char *stop;

    printf("%d\n",strtol(buffer, &stop, 8));

    printf("%s\n", stop);

    输出结果:

    543

    9cend$3

    --------------------------------------------------------

    原文

    http://hi.baidu.com/qwpsmile/item/78098326af14368e9d63d179

    http://hi.baidu.com/qwpsmile/item/78098326af14368e9d63d179

  • 相关阅读:
    My 1st webUI try
    option(recompile)
    Add&Delete WindowService
    powershell
    bootstrap模态框,等待遮盖层
    spring-boot通过@Scheduled配置定时任务
    bootstrap-table的一些参数配置
    $('xx')[0].files[0]的意思
    Go国内镜像
    基础语法-defer使用(12)
  • 原文地址:https://www.cnblogs.com/mydomain/p/3114298.html
Copyright © 2011-2022 走看看