有两个错误,改正如下:
#include<stdio.h>
#include<string.h>
int main()
{
void number(char *p);
char str[100];
gets(str); //用scanf输入,当遇到空格后,输入结束,输入字符串只有第一个空格之前的数据,改用gets输入
number(str);
return 0;
}
void number(char* p)
{
int upper=0,lower=0,space=0,digit=0,other=0;
while (*p != '\0') //字符串的结束符号位"\0"
{
if (('A' <= *p) && (*p <= 'Z'))
upper++;
else if (('a' <= *p) && (*p <= 'z'))
lower++;
else if (*p ==' ')
space++;
else if (('0' <= *p) && (*p <= '9'))
digit++;
else
other++;
p++;
}
printf("大写字母有:%d个小写字母有:%d个﹐空格有:%d个数字有:%d,其他有:%d",upper,lower,space,digit,other);
}
你的效果: