Is there a function or library that can convert any (default, octal, hex, …) integer in C given as a char[] into an unsigned long long int ?
Examples:
1
1l
1ul
42e+10
0x2aLL
01234u
...
atoi has some problems with 0x… and the suffixes u/l.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
strtoullis about as close as it gets. This will stop at the suffix, but since you’re always producing anunsigned long long, you don’t really care about the suffix anyway. I don’t believe it will work with42e+10either — although the value that produces is an integer, C and C++ only define the ‘e’ notation for floating point numbers.Other than that, you need/want to pass
0as the conversion base, in which case it implements the usual C convention that a leading0signals octal,0xsignals hexadecimal, and1-9signal decimal.