輸入一串字符,包括大寫字母、小寫字母、數字、空格和其他字符


#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;
}

輸出結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM