源程序:
#include <stdio.h>
int main()
{
int upper=0,lower=0,digit=0,space=0,other=0,i=0;
char *p,s[80];
printf("請輸入一串字符,包括大寫字母、小寫字母、數字、空格和其他字符,不超過80個:\n");
while ((s[i]=getchar())!='\n')
i++;
p=&s[0];
while (*p!='\n')
{
if (('A'<=*p) && (*p<='Z'))
++upper;
else if (('a'<=*p) && (*p<='z'))
++lower;
else if (*p==' ')
++space;
else if ((*p<='9') && (*p>='0'))
++digit;
else
++other;
p++;
}
printf("大寫字母個數:%d\n",upper);
printf("小寫字母個數:%d\n",lower);
printf("數字個數:%d\n",digit);
printf("空格個數:%d\n",space);
printf("其他字符個數:%d\n",other);
return 0;
}
運行結果: