while(str[i]!='\0')
{
if(str[i]!=' ')
{
count++;
}
i++;
}
this loop works or chnage your for loop to
for(i=0; i<strlen(string1); i++)
{
if(string1[i] != ' ' && string1[i] != '0')
counter1++;
}
since you used
for(i=0; i<N; i++)
where N=100
and c will not check for out of bound access therefore the loop continues till i=100
this resulted in count=100-number of spaces
.