Hi all. First of all sorry for this long post, but I try to explain the question at best.
I have a (const char *) to parse that contains not a string, but a byte array (it stores binary data chunk).
I have to look for the LAST bytes (last 2, last 3, etc etc) until I will find the same sequence in another part of the same bytearray. I make an example to clarify. Consider this possible (and short) byte array to parse
13 22 15 2C 91 65 54 B1 FF 91 65 54 B1 FF
the longest match possible to find is "91 65 54 B1 FF". Infact if you mentally cut the last bytes matched you would obtain:
13 22 15 FF
91 65 54 B1 FF
(so: match will be: longhest part of array with match is 5bytes long and match is located at offset 5) (note in order to count offset you must count bytes remained after "mental truncation" until the first byte of match occurs. In this case "91" of "91 65 54 B1 FF" is the 5th byte counting from end.
--------------------------------------------------------
I hope I clarified what I am trying to do. Whell my question is about the way to do it
I wanted to use pointers like:
char * p2 = my_byte_array_to_parse + (dim_array -1);
char * p1 = p2--;
and start from those points of string.
but a friend says me (without explaination) to avoid to move pointers (he sais: pointers are like nature: don't try to force them). So I'd like your opinion
--------------------------------------------------------
Another question related to the first one: a code like this one is correct?
1 2 3 4
|
char array [10] = {0,1,2,3,4,5,6,7,8,9};
int value = 4;
char * p = &array;
p += value;
|
if correct p should point to array[4] but I am not sure it is possible to do so.