请问统计空格数量哪里出错了

#include
#include
int main()
{int blank=0;int digit=0;int other=0;
int len;
char q[100];
scanf("%s",&q);
len=strlen(q);
for(int i=0;i
if(q[i]==' ') blank++;
else if(q[i]>='0'&q[i]<='9') digit++;
else other++;
}
printf("blank = %d, digit = %d, other = %d",blank,digit,other);
return 0;
}

1.想统计字符中空格 数字和其他的数量,到空格就跳出循环了 是哪儿出错了
2.在输入的字符长度未知时 char q[100];这一句应该怎么改 这么写是可以的吗

修改说明见注释,供参考:

#include<stdio.h>
#include<string.h>
int main()
{
    int blank=0;int digit=0;int other=0;
    //int len;可以省略
    char q[100];
    scanf("%[^\n]", q);//scanf("%s",&q); q 是字符串数组名,即是指针,所以这里的'&'符省略。
                    //scanf()函数读入字符串,如需要读入空格等字符,不能用 %s,改为 "%[^\n]"。
    //len=strlen(q);//可以省略
    for(int i=0;q[i] != '\0';i++){//for(int i=0;i<len;i++) 字符串是否结束用 '\0' 判断即可。
        if(q[i]==' ')
           blank++;
        else if(q[i]>='0' && q[i]<='9')   // && 左右两边都要满足
           digit++;
        else
           other++;
    }
    printf("blank = %d, digit = %d, other = %d",blank,digit,other);
    return 0;
}

你strlenp测的是指针的长度。一般都是4

else if(q[i]>='0'&q[i]<='9') digit++; 中中间少了个&,else if(q[i]>='0' && q[i]<='9') digit++;
scanf以空白字符为分隔,也就是接收不了空格。scanf("%s",&q);中q已经是指针了,不需要&
改用getline,或者
char ch;
while ((ch = getchar()) != '\n')
{
对ch进行判断和统计,不用q了。
}