Page 1 of 1

finding sub_array in array

Posted: Thu May 27, 2010 7:11 pm
by Eric
Hello,

I need to verify the occurence of a 8 byte sub-array in another 130 bytes array.
I can't use the C-function strstr because there are zero bytes in both arrays.
Can anybody show me the way how to do this?

Best regards,

Eric

Re: finding sub_array in array

Posted: Fri May 28, 2010 8:55 am
by Benj
Hello Eric,

Its best to do this kind of thing byte by byte.

Eg you start a counter variable at 0 the start of the array. Then move through the array until you find the first character that matches the first character of your string. Then move to the second character if this does not match the second character in your string then does it match the first. And so on until you have found the entire string.

idx = 0
found = 0
character = 0
while found = 0
{
if string[idx] = compare[character]
yes: character = character + 1
no: character = 0

if character = length of search string
yes: found = 1

idx = idx + 1
}

Re: finding sub_array in array

Posted: Fri May 28, 2010 9:11 am
by Eric
Thanks Ben, I will give it a try.

Rgds,

Eric