新手求助一个问题 编写一个用来统计输入统计的各个数字、空白符(空格、制表符、换行符)以及所有其他字符出现次数的程序
这下面是我编的代码。语法没报错。但是没结果,不知道哪里有问题。请各位大神帮我指正下。万分感谢!#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int spac=0;
int others=0;
int number[10];
char line[100];
int i=0;
char t;
char *pS={NULL};
printf("please input the line:");
while((*fgets(line,100,stdin))!='\n')
{
pS=(char*)malloc(strlen(line));
strcpy(pS,line);
}
printf("%s",pS);
while(1)
{
t=*pS;
if(t>=0||t<=9)
{
switch(t)
{
case 0:
number[0]++;
break;
case 1:
number[1]++;
break;
case 2:
number[2]++;
break;
case 3:
number[3]++;
break;
case 4:
number[4]++;
break;
case 5:
number[5]++;
break;
case 6:
number[6]++;
break;
case 7:
number[7]++;
break;
case 8:
number[8]++;
break;
case 9:
number[9]++;
break;
}
}
else if(t==' '||t=='\t')
spac++;
else others++;
if(t=='\n')
break;
}
printf("%d",spac);
printf("%d",others);
for(i=0;i<10;i++)
{
printf("%d",number[i]);
}
return 0;
}