C语言:字符串转为long long --- atoll函数

源码:

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

int main()
{
	unsigned long long tmp_ll;

	tmp_ll = atoll("0000000000000002");
	printf("tmp_ll : %lld \n", tmp_ll);

	tmp_ll = atoll("122323");
	printf("tmp_ll : %lld \n", tmp_ll);
	
	tmp_ll = atoll("122323344");
	printf("tmp_ll : %lld \n", tmp_ll);

	tmp_ll = atoll("112233445566");
	printf("tmp_ll : %lld \n", tmp_ll);
	
	tmp_ll = atoll("11223344556677");
	printf("tmp_ll : %lld \n", tmp_ll);
	
	tmp_ll = atoll("1122334455667788");
	printf("tmp_ll : %lld \n", tmp_ll);
	
	tmp_ll = atoll("11223344556677ff");
	printf("tmp_ll : %lld \n", tmp_ll);
	
}

运行:

root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/03_test/01_C/3_file# gcc -o 6 6.c
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/03_test/01_C/3_file# ./6
tmp_ll : 2 
tmp_ll : 122323 
tmp_ll : 122323344 
tmp_ll : 112233445566 
tmp_ll : 11223344556677 
tmp_ll : 1122334455667788 
tmp_ll : 11223344556677 
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/03_test/01_C/3_file# 

转化出来的是长长整型十进制,不是十六进制。所以字符串中不能出现字母。

很基本的C语言知识。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值