int main(void)
{
char a[100];
printf("please input char:\n");
scanf("%s", &a);
f(a);
return 0;
}
void f(char *a)
{
int i = 0;
int space = 0, line = 0, others = 0;
while(a[i] != '#')
{
switch(a[i])
{
case ' ': space++; break;
case '\n': line++; break;
default : others++; break;
}
i++;
}
printf("space count is:%d\n", space);
printf("line count is:%d\n", line);
printf("other count is:%d\n", others);
}
求字符数目,输入字符串时显示Segmentation fault (core dumped),请问是什么原因?应该怎么改?