There is a strtol() function to convert a string to a long.
Meh - that’s taking the easy way out
Be sure to read the man page on setting the base…
long int strtol(const char *nptr, char **endptr, int base);
The string may begin with an arbitrary amount of white space (as determined by isspace(3)) followed by a single optional ‘+’ or ‘-’ sign. If base is zero or 16, the string may then include a “0x” prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is ‘0’, in which case it is taken as 8 (octal).
The 0x at the start should force it to base 16 if you leave the base at 0, but to be safe I’d set it to 16 regardless.
However, all that extra code to convert other bases that you don’t need would add extra bulk to your program - better to have a single small lightweight routine that just handles the one base you’re working with, yes?