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?
If you pass 0 as the base argument, strtoull recognizes 0x and 0 prefix to indicate hex and octal, respectively, and defaults to decimal otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With