My function is supposed to have a successful start sequence when ever it encounters 0 0 0 0 1 1 0 but when i input these numbers the number of successful start sequence does not change However that doesn't stop it from compiling and I can't spot where the mistake Ive made is.
main()
{
int i,num;
int array[300];
i=0;
num=0;
while(i<100)
{
scanf("%d",&array[i]); //input
i++;
//checks for start sequences while making sure there is atleast 8 numbers input
if((i>=8)&&((array[i-1])==0)&&((array[i-2])==1)&&((array[i-3])==1)&&((array[i-4])==0)&& ((array[i-5])==0)&&((array[i-6])==0)&&((array[i-7])==0))
{
num++;//counts the number of successful startsequences
}
printf("Number of valid start sequences is %d\n",num);
}
}
You're facing off-by-one error.
Remember, the element number
n
in array is marked byn-1
the index.for example,
never checks
array[0]
element, does it?Maybe, you want to start with changing
if((i>=8)
toif((i>=7)