I have a char array representing a double precision floating point number in hex form.
char *hex = ""402499999999999A"
I want to extract each char in hex as its own char array and read it into an unsigned int num. For example, I tried
sscanf((char *)&hex[3], "%X", &num);
But this doesn’t give me the 4th char as an individual char array, it gives me the sub char array from the 4th position on, which I suppose is because arrays are given by the pointer of their first element.
Is there a better way to do this? I looked at strcpy and it seems that I can only copy the first n chars, so that’s no good.
You can do this in many ways. One way is as follows (which is the correct way of how you were doing it):
and a more efficient solution:
This is just a sample, though. In truth you need to take care of invalid input and lower cases if that is a possibility.