scanf a big hexadecimal value

痴心易碎 提交于 2021-02-05 07:52:12

问题


I have a issue trying to use scanf to get a big hexadecimal num (12 chars) from the user.

it seems to only get the last 8 chars, eg - ABFFFFFFFF will become 0000FFFFFFFF.

this is my code -

unsigned long long address;
scanf("%x",&address);
printf("Address: %#014x", address);

for this input: "ABFFFFFFFF" the output would be:

Address: 0x0000ffffffff

i have tried playing a bit with the scanf format, but to no avail.


回答1:


You must use "%llx" for both scanf format and printf. See the manual page for additional details.



来源:https://stackoverflow.com/questions/30561882/scanf-a-big-hexadecimal-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!