C (gcc on linux): How do i convert a hex string "0xfffffff" to an integer?

c, gcc

Solution

The other, quasi-portable, way is `strtol` and it's fellows `strtoul`, `strtoll`, and `strtoull`. They look like:

long
strtol(const char * restrict nptr, char ** restrict endptr, int base);

Use is a little strange. The first argument is the string you want to convert, and the third is the base, which for hex would be 16. The second argument is used for debugging: it can point to the first character in the hex string which failed to convert.

Problem

C (gcc on linux): How do i convert a hex string "0xfffffff" to an integer ?

Original source