im trying to fill an unsigned char array with hex values (0x12 0x23 etc)
read in from a text file, i have searched this forum, but not found exactly what i need and my limited knowledge prevents me from adapting the code snippets i found to my needs. the code snippet i have is as follows, i am not posting the whole program because previously i have been flamed for doing that.
Code:
FILE *file;
U8 instructions;
U8 hexbyte = 0x00;
U8 hexnibh = 0x00;
U8 hexnibl = 0x00;
U8 memory[10] = {0x00};
U8 progmemory[10] = {0x00};
U8 convert = 0x00;
U8 i = 0x00;
file = fopen("f:\\L_Endian.txt", "r");
while(! feof(file)){
fscanf(file, "%c", &memory[instructions++]);
hexnibh=memory[convert++];
hexnibh =(hexnibh - '0');
hexnibh = (hexnibh << 4);
fscanf(file, "%c", &memory[instructions++]);
hexnibl=memory[convert++];
hexnibl =(hexnibl - '0');
hexbyte = (hexnibh ^ hexnibl);
progmemory[i++] = hexbyte;
}
fclose(file);
what i want to do is read in a file with numbers like 1234567890...
convert to hex values
into an array[0x12]
array[0x34]
array[0x56]
array[0x78]
array[0x90]
each element being an unsigned char type
this code nearly works except i get extra (unwanted)byte 0x0A and in the array
if thas has been done allready can you point me to the location please
luigi