This code:
#include <stdio.h>
int main(void)
{
int array[] = { 0, 0, 0, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, };
int a_size = sizeof(array) / sizeof(array[0]);
int i = 0;
while (i < a_size)
{
if (array[i] == 0)
{
int j;
for (j = i; j < a_size; j++)
if (array[j] != 0)
break;
printf("%d\n", j - i);
i = j;
}
else
i++;
}
return 0;
}
produces this output:
4
1
12
If that's what you want, that's roughly what you need. If it is not what you want, you need to explain more clearly what it is that you want.
Revised code for revised expected output:
#include <stdio.h>
int main(void)
{
int array[] = { 0, 0, 0, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, };
int a_size = sizeof(array) / sizeof(array[0]);
int i = 0;
while (i < a_size)
{
if (array[i] == 0)
{
int j;
for (j = i; j < a_size; j++)
if (array[j] != 0)
break;
int k = j - i;
while (k > 0)
printf(" %d", k--);
i = j;
}
else
{
printf(" '");
i++;
}
}
putchar('\n');
return 0;
}
Revised output:
4 3 2 1 ' 1 ' 12 11 10 9 8 7 6 5 4 3 2 1 '