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转换为十进制整数

 

posted @ 2014-12-03 21:33  BB的想法  阅读(141)  评论(0编辑  收藏  举报