Hi ;
Im trying to implement in c a function that's called Sniffer which gets two inputs and returns the correspond matrix.
First input is an integer binary array values (just zero or one)
second input is your searched word ( the word you choose it as argument to your function )
the functionally of the function ( what the function does) :
searching for occurrence of the given word within your given binary array. at each occurrence of your word there's always follows 8 bits following it, assume that always the input is correct (it means that there's no possibility two occurrence occur one after the other without at least there's space 8bits (8 binary values)!). then the function must return a matrix(integer matrix) of those followed 8bit for each occurrence of the word sorted corresponded by every row of the matrix. (the functions returns just the first 8bit followed each occurrence of the Searched word)
this means:
First row has first 8 followed bit on first occurrence of the word.
Second row has first 8 followed bit on second occurrence of the word.
Third row has first 8 followed bit on third occurrence of the word.
Fourth row has first 8 followed bit on fourth occurrence of the word.
etc ...

I will elaborate by examples:
function structure is
Code:
int ** SnifferPattern(int* givenArray ; int* SearchedWord);
//it returns the corresponded matrix so used int** ;
#1
Code:
givenArray={1,0,1,0,1,1,1,1,1,1,1,1,0,0};
SearchedWord={1,0,1,0};
so the function returns a matrix(size 1x8 - 8 corresponds to 8followed bit) the first row is
{1,1,1,1,1,1,1,1} which it's the first 8 bit followed the word 1010
the matrix here with one row because there's just one occurrence
of the SearchedWord in the given array.
example 2:
#2
Code:
givenArray={1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0,1,0,1,0,1,0};
SearchedWord={1,1,0,0}
so the function returns a matrix the first row is
{1,1,1,1,1,1,1,1} which it's the first 8 bit followed the word 1010 for the first occurrence.
for the second occurrence we see the word appear , so the second row of the returned matrix(size 2x8) will include the first 8bit followed the word 1010 of the second occurrence. so second row of the matrix is
 {1,0,1,0,1,0,1,0}
so the returned matrix (size 2x8) has two rows (because there's two occurrences of the SearchedWord) which each row corresponds to each occurrence of the SearchedWord.
third example:
#3
Code:
givenArray={1,1,1,0,1,1,1,1,1,1,1,1,0,0};
SearchedWord={0,1,0}
so the function returns a matrix zero row (like an array with zero values) size 1x8 (8 columns is corresponded to 8followed bit).
there's no occurrence of the SearchedWord within the givenArray so we return a zero matrix.
There's no overlap between the occurrences of the searchedWords , so we assume always correctness of input.


I will explain my algorithm (a pleasure if there's another suggestions more compatible to my case)
My algorithm is searching for the word by binary search and then take at every occurrence the first followed 8bit . but it sounds much hard to complete with this.
I implemented the binary search and I'm stuck how to continue in order to get correct outputs (matrix of the first followed 8bit at each occurrence of the searched word) :
Code:
void binary_search(int* givenArray, int* target){
    int bottom= 0;
    int mid;
    int top = size - 1;


    while(bottom <= top){
        mid = (bottom + top)/2;
        if (strcmp(&givenArray[mid], target) == 0){
            printf("%s found at location %d.\n", target, mid+1);
            break;
        }
        if (strcmp(&givenArray[mid], target) == 1){
            top= mid - 1;
        }
        if (strcmp(&givenArray[mid], target) == -1){
            bottom= mid + 1;
        }
    }
}


int main(){


    int givenArray[14]={1,0,1,0,1,1,1,1,1,1,1,1,0,0}; //given array 
    int SearchedWord[4]={1,0,1,0} //given word to search about it within given array
    int i = 0;
   binary_search(givenArray, SearchedWord);
    return 0;
}
Any help in this please? maybe converting the binary array values to string will make the implementation more easy? I feel that the problem is trivial and easy but I went to complex approach that will take to much time to implement.

Appreciate for any help guys - much thanks.