Problem to set pointer to last position of string

1
2
3
unsigned char * p,end;
p = *pBitmap;
end = *p+(bmpfile->dib.raster_size-1);

bmpfile->dib.raster_size is 33554432
p is 0x600020 '\377' <repeats 8188 times>, "\276q\276q"

p should point to begin of the string. I expect that if I add
33554432-1 to p so it should point to last character of *pBitmap.

But I don't think it works.

*p refers to 255 '\377' (I think it means it points to 256th position). But end points to 254 'ţ' which should not be so. I expect *p should point to 0th element of char array and end should point to 33554432th element, so I should rather see something like end to be 33554431 '\377' ... So how what I do wrong?
Let me show what actually happens in your code:
1
2
unsigned char * p;
unsigned char end;
Do you see the problem now?
I see. Thanks for simple explanation. But one more problem. end does not point to last char at the moment.

end is (unsigned char *) 0x20000fe '\377' <repeats 4890 times>

But I am too tired to think, gotta sleep.
There are two thing which are wrong with your code:
1) You do not need to dereference starting pointer. Just add buffer size to it and you will get end pointer.
2) To get value of pointer, you need to cast it to void*. Otherwise it will be threated ass a c-string which it is not.
Thanks I see the mistake now. Actually I want to loop the p until p<end to loop the string. So I am not getting the value at the moment.
Topic archived. No new replies allowed.