如题所述
#include <stdio.h>
#include <conio.h>
#define LEN 50
int main (void) {
//char str[LEN];
char str[LEN] = "5DQj$6X MDaCdj @9IFazB";
char *p = str;
int capCnt, lowCnt, numCnt, othCnt; /*分类计数*/
capCnt = lowCnt = numCnt = othCnt = 0;
//puts ("输入字符串:");
//gets (str);
puts (str);
while (*p) {
if (*p>='A'&&*p<='Z')
capCnt++;
else if (*p>='a'&&*p<='z')
lowCnt++;
else if (*p>='0'&&*p<='9')
numCnt++;
else
othCnt++;
p++;
}
putchar ('\n');
printf ("大写字母%d个\n", capCnt);
printf ("小写字母%d个\n", lowCnt);
printf ("数字%d个\n", numCnt);
printf ("其他字符%d个\n", othCnt);
putchar ('\n');
getch (); /*屏幕暂留*/
return 0;
}
#include <conio.h>
#define LEN 50
int main (void) {
//char str[LEN];
char str[LEN] = "5DQj$6X MDaCdj @9IFazB";
char *p = str;
int capCnt, lowCnt, numCnt, othCnt; /*分类计数*/
capCnt = lowCnt = numCnt = othCnt = 0;
//puts ("输入字符串:");
//gets (str);
puts (str);
while (*p) {
if (*p>='A'&&*p<='Z')
capCnt++;
else if (*p>='a'&&*p<='z')
lowCnt++;
else if (*p>='0'&&*p<='9')
numCnt++;
else
othCnt++;
p++;
}
putchar ('\n');
printf ("大写字母%d个\n", capCnt);
printf ("小写字母%d个\n", lowCnt);
printf ("数字%d个\n", numCnt);
printf ("其他字符%d个\n", othCnt);
putchar ('\n');
getch (); /*屏幕暂留*/
return 0;
}
温馨提示:答案为网友推荐,仅供参考