简体   繁体   中英

strtoull based on the input string

I have a tool called romflasher that takes two string commandline parameters --s-addr0 and --e-addr0

romflasher --s-addr0 0x1c40000 --e-addr0 0x1e40000

Inside my program romflasher.c

 char s_addr_0[256];
 char e_addr_0[256];

 uint32_t start_addr = strtoull(s_addr_0,(char**)NULL,16);
 uint32_t end_addr   = strtoull(e_addr_0,(char**)NULL,16);

This works fine as long as the user specifies the address as hexadecimal.I want to give the user the option to specify it in both decimal as well as hexadecimal.Is there a function that will do the appropriate string conversion based on the presence of '0x' prefix to the correct base?

如果传递0作为base参数,则strtoull识别0x0前缀以指示十六进制和八进制,否则默认为十进制。

为什么不写一个包装器函数到strtoull(mystrtoull)并检测字符串中的0x并相应地将base参数传递给strtoull?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM