Hello
I've googled this but I'm not getting much joy.
Does anyone know of an easy way to read/write hex from/to a file in C?
Thank you.
This is a discussion on Read/Write hex from/to a file in C? within the C Programming forums, part of the General Programming Boards category; Hello I've googled this but I'm not getting much joy. Does anyone know of an easy way to read/write hex ...
Hello
I've googled this but I'm not getting much joy.
Does anyone know of an easy way to read/write hex from/to a file in C?
Thank you.
fscanf(f, "%x", &var); maybe
If I have eight hours for cutting wood, I spend six sharpening my axe.
Thank you for your reply.
So if I have a text file called plaintext.txt with the following HEX:
0123456789ABCDEF
Should the following code work?
Thank youCode:FILE *fp; unsigned char message[8]; fp=fopen("c:\\plaintext.txt", "r"); fscanf(fp, "%x", &message); fclose(fp);
Last edited by MrSteve; 03-25-2008 at 04:30 PM.
no...Should the following code work?
read the scanf format description
read about %x format
read about maximum integer value
try to figure out your problems...
If I have eight hours for cutting wood, I spend six sharpening my axe.
Here is the code, like yours, but it compiles:
Here is the output:Code:#include <stdio.h> int main(void) { FILE *fp; unsigned int message; fp=fopen("c:\\plaintext.txt", "r"); fscanf(fp, "%x", &message); printf("%x ", message); fclose(fp); return 0; }
Go from there. Looks to me like it's only printing the last 8 digits.Code:89abcdef