#include <stdio.h>
#include <conio.h>
#define LEN 50
int main (void) {
char str[LEN];
char *p = str;
char cap[LEN], low[LEN], num[LEN], space[LEN], oth[LEN]; /*分类存储字符*/
int capCnt, lowCnt, numCnt, spaceCnt, othCnt; /*分类计数*/
capCnt = lowCnt = numCnt = spaceCnt = othCnt = 0;
puts ("输入字符串:");
gets (str);
while (*p) {
if (*p>='A'&&*p<='Z') {
cap[capCnt] = *p;
capCnt++;
}
else if (*p>='a'&&*p<='z') {
low[lowCnt] = *p;
lowCnt++;
}
else if (*p>='0'&&*p<='9') {
num[numCnt] = *p;
numCnt++;
}
else if (*p==' ') {
space[spaceCnt] = *p;
spaceCnt++;
}
else {
oth[othCnt] = *p;
othCnt++;
}
p++;
}
*p = cap[capCnt] = low[lowCnt] = num[numCnt] = space[spaceCnt] = oth[othCnt] = '\0'; /*字符串结束符*/
putchar ('\n');
printf ("大写字母%d个:%s\n", capCnt ,cap);
printf ("小写字母%d个:%s\n", lowCnt ,low);
printf ("数字%d个:%s\n", numCnt ,num);
printf ("空格%d个:%s\n", spaceCnt ,space);
printf ("其他字符%d个:%s\n", othCnt ,oth);
putchar ('\n');
getch (); /*屏幕暂留*/
return 0;
}
运行结果
