scanf一个大的十六进制值 [英] scanf a big hexadecimal value
本文介绍了scanf一个大的十六进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用scanf从用户那里获取一个大的十六进制数字(12个字符)时遇到问题.
I have a issue trying to use scanf to get a big hexadecimal num (12 chars) from the user.
似乎只能获取最后8个字符,例如-ABFFFFFFFF将变为0000FFFFFFFF.
it seems to only get the last 8 chars, eg - ABFFFFFFFF will become 0000FFFFFFFF.
这是我的代码-
unsigned long long address;
scanf("%x",&address);
printf("Address: %#014x", address);
对于此输入:"ABFFFFFFFF",输出为:
for this input: "ABFFFFFFFF" the output would be:
地址:0x0000ffffffff
Address: 0x0000ffffffff
我尝试过用scanf格式播放,但无济于事.
i have tried playing a bit with the scanf format, but to no avail.
推荐答案
scanf格式和printf都必须使用%llx".有关更多详细信息,请参见手册页.
You must use "%llx" for both scanf format and printf. See the manual page for additional details.
这篇关于scanf一个大的十六进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文