麻烦再给看看啊,还是有问题:
#include <stdio.h>
main()
{
char str[50];
int i=0;
int letter_sum=0,
number_sum=0,
space_sum=0,
other_sum=0;
printf("Please input a string of characters:\n");
scanf("%c",&str[i]);
while(str[i]!='\r')
{
i++;
scanf("%c",&str[i]);
}
str[i]='\0';
for(i=0;str[i]=='\0';i++)
{
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
letter_sum++;
else if(str[i]>='0'&&str[i]<='9')
number_sum++;
else if(str[i]==' ')
space_sum++;
else
other_sum++;
}
printf("There are %d letters in the string.\n",letter_sum);
printf("There are %d numbers in the string.\n",number_sum);
printf("There are %d spaces in the string.\n",space_sum);
printf("There are %d other characters in the string.\n",other_sum);
}