首页 > 代码库 > strtol()函数

strtol()函数

#include <stdlib.h>
#include <stdio.h>

int main()
{
 char a[] = "100";
 char b[] = "100";
 char c[] = "0x11";
 int x, y, z;
 x = strtol( a, NULL, 10 );
 y = strtol( b, NULL, 2 );
 z = strtol( c, NULL, 16 );

 printf( "x = %d\n", x );
 printf( "y = %d\n", y );
 printf( "z = %d\n", z );
}

输出:x = 100

      y = 4

      z = 17

 

将字符串根据base转换为十进制整数

 

strtol()函数