Convert hex back to int?
Hi. I have a file to read, in this format:
My function is this:
Now this reads all values fine and stores them as ints, but the last hex value is always stored as 0. Is there any way to get it to parse the string in as an int?
void Tile::ReadTileData(char* line)
buffer = strtok (line, ",");
while (buffer != NULL)
buffer = strtok (NULL, ",");
You need to recognize the prefix 0x. Then you parse the remainder as a hex string. If you used C++, you can use stringstream's setbase to do that.
Or use "strtol" which automatically recognizes decimal, hex and octal numbers unless you specify a base.