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
finding sub_array in array
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: finding sub_array in array
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
}
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
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel