how can i read an hex numbers from file?
how can i read an hex numbers from file?
...
fscanf (fpointer, "%x", &i);
?
This works for me...
int amount_of_numbers, number[100]
FILE *input;
input = fopen("file.txt", "r");
if (input==NULL) {
exit(1);
}
for (i=0; i<amount_of_numbers; i++) {
fscanf(input, "%x", &number[i]);
}
fclose(input);
'%x' tells scanf to read in a hex number rather than an integer.
the array 'number' should now contain the values in hex in the order they were in the file.
Hope this works...
i tried this method in the first time but for some reason it's not read the same numbers that i saw in the hex editor
Oooooooh... that's what you want to know.
Try this...
Not really sure if this program will work, but maybe it gets the point across? Let's assume this program is named disphex.exe then...Code:#include <stdio.h> #define NUMS 10 typedef char byte; int main (int argc, char * args[]) { FILE * f; byte b; putc ('\n'); f = fopen (args[1], "r"); for (i = NUMS; i != 0; i--) { b = fgetc (f); printf ("%3.2X", (int) b); } putc ('\n'); return; }
disphex storm.cam
will display the first ten bytes of the file storm.cam in hex format.
in what your method is difference from the other method
and for what the %3.2X?