Yes, that is the approach that I would have taken

Let's take another look at the condition of your original for loop:

Code:

for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i){

What it says is this: loop from the first character until a character that is not in the range '0' to '9' is found. This works great if your input consists entirely of digits from '0' to '9', e.g., "123" as you would loop over the entire input string. But suppose your input consists of the non-decimal range of hexadecimal digits, e.g., "ABC". Your loop will stop immediately because 'A' is a character that is not in the range '0' to '9'. Therefore the result is 0, which is obviously wrong.

Compounding this problem, within the loop body, you check to see if the character is a valid hex digit in the sense of whether it is a digit that is among the alphabetic hexadecimal digits 'A' to 'F'. Of course, knowing that within the loop body the character is surely in the range '0' to '9', it follows that it is surely "not a valid hex digit", therefore 0 is returned. Consequently, your function always returns 0, because either the character is not in the range of '0' to 9' hence 0 is returned, or it is in the range of '0' to '9' but not in the range of 'A' to 'F' (which is always true), hence 0 is returned.