I have followed the tutorial and thought I would attempt to modify the Input/Output with files example to read some information about a file. For instance bytes 0-12 contain title, fairly easily achieved this with cout in a loop. But I want to read bytes 128-132 and have them as one hex value but I have tried to work around this but keep getting invalid conversion errors or invalid types for array subscript.
Can anyone suggest a way to do this or what I am doing wrong please?
reading 128-132 in one go... that is 5bytes.. correct..!!
read five bytes in a unsigned char array and combine them.
give you an example for 4bytes and do this for any number of bytes.
lets say your file has 12345678 (0xBC614E) (00000000-10111100-01100001-01001110)
if you read these four bytes your array will get this:
1 2 3 4 5 6 7 8 9 10
unsignedchar arr[10];
fread(arr, sizeof(unsignedchar), 4, fp);
//the array will have these values
//arr[0]= 0;
//arr[1]= 188;
//arr[2]= 97;
//arr[3]= 78;
int value = arr[0]<<24 | arr[1]<<16 | arr[2]<<8 | arr[3];
for (int count=128; count<=131; count++)
{
for (int loop=0; loop<=4; loop++)
{
info[loop] = memblock[count];
}
}
You can't index "info", it is not an array (or even a pointer).
You have a two-dimensional loop structure for a one-dimensional problem.
(And the inner loop would execute 5 times anyway.)
You mean something like this: