If it cant find them in that section before 7,37, I dont want it to go any further, how would I know when to stop?
When it finds n consecutive 0's, return
Code:
#include <stdio.h>
int find_n(int *, int, int, int);
int main(void)
{
static int list[] = {0,8,38,0,0,0,0,0,0,7,37,0,0,0,0,0,0};
printf("First 6 0's starting at index %d\n",
find_n(list, 17, 0, 6));
return 0;
}
int find_n(int *list, int length, int value, int n)
{
int i;
int count = 0;
for (i = 0; i < length; i++)
{
if (count == n)
return i - count;
if (list[i] == value)
count++;
else
count = 0;
}
return -1;
}