I'm trying to read a binary file and convert each byte inside to 2hex digits, but when
I get to a space my program prints '0' when it should be '20' and it does this for every 20
my output 0 17 FF FF FF FF 0 0 17 FF FF FF FF FF 0 0 0 FF 0 0
output from
http://www.percederberg.net/tools/text_converter.html20 17 FF FF FF FF 20 20 17 FF FF FF FF FF 20 20 20 FF 20 20
does anyone know whats going on?
file =
Code
ÿÿÿÿ ÿÿÿÿÿ ÿ
Code
//Read the test.bin file!!
#include<stdio.h>
char initial[] = "test.bin";
struct rec{
unsigned char mydata;
};
int readfile(char []){
int counter;
FILE *ptr_myfile;
struct rec my_record;
ptr_myfile=fopen(initial,"r");
if (!ptr_myfile){
printf("Unable to open file!");
return 1;
}
for ( counter=1; counter <= 10; counter++){
fread(&my_record,sizeof(struct rec),1,ptr_myfile);
printf("%X\n",my_record.mydata);
}
fclose(ptr_myfile);
return 0;
}
int main(){
readfile(initial);
return 0;
}
This post was edited by bakalolo on Feb 22 2014 01:33pm