read 2 bytes in hexadecimal base and convert into decimal using C language fscanf

By Mario Francis

Well as said Im using C language and fscanf for this task but it seems to make the program crash each time then its surely that I did something wrong here, I havent dealed a lot with this type of input read so even after reading several topics here I still cant find the right way, I have this array to read the 2 bytes

char p[2];

and this line to read them, of course fopen was called earlier with file pointer fp, I used “rb” as read mode but tried other options too when I noticed this was crashing, Im just saving space and focusing in the trouble itself.


later to convert into decimal I have this line (if its not the EOF that we reached)

v = strtol(p, 0, 10);

Well v is mere integer to store the final value we are seeking. But the program keeps crashing when scanf is called or I think thats the case, Im not compiling to console so its a pitty that I cant output what has been done and what hasnt but in debugger it seems like crashing there

Well I hope you can help me out in this, Im a bit lost regarding this type of read/conversion any clue will help me greatly, thanks =).

PS forgot to add that this is not homework, a friend want to make some file conversion for a game and this code will manipulate the files needed alone, so while I could be using any language or environment fo this, well I always felt better in C language =)

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273