- #include <stdio.h>
- #include <string.h>
- int main(int argc, const char * argv[]) {
- char str[1000] ;
- char *p = str;
- int a =0,b=0,c=0,d=0;
- printf("请输出字符串\n");
- gets(str);
- for (p=str; p<&str[strlen(str)]; p++) {
- printf("%c\t",*p);
- switch (*p) {
-
- case 'A':
- a++;
- break;
-
- case 'B':
- b++;
- break;
-
- case 'C':
- c++;
- break;
-
- case 'D':
- d++;
- break;
- }
- }
- printf("\n");
- printf("%d,%d,%d,%d\n",a,b,c,d);
- return 0;
- }
复制代码 |