| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 376 人关注过本帖
标题:统计字符,请大家帮我找找错
只看楼主 加入收藏
雾雨淼淼
Rank: 2
来 自:甘肃金昌
等 级:论坛游民
帖 子:85
专家分:89
注 册:2010-8-17
结帖率:100%
收藏
已结贴  问题点数:30 回复次数:3 
统计字符,请大家帮我找找错
程序如下:
# include <stdio.h>
void main()
{
    int num,alp_a,alp_A,oth;
    char a;
    num=0;
    alp_a=0;
    alp_A=0;
    oth=0;
    printf("本程序负责统计输入的字符的类型\n");
    printf("类型有大写字母、小写字母、数字、其他字符\n");
    printf("请输入字符,以ESC退出\n");
    while((a=getchar()))
    {
        switch (a)
        {
            case a>='a' && a<='z':
                alp_a ++;
                break;

            case a>='A' && a<='Z':
                alp_A ++;
                break;
            case a>='0' && a<='9':
                num ++;
                break;
            default:
                oth ++;
                break;
        }
        printf("请输入下一个字符:\n");
    }
    printf("统计结果如下:\n");
    printf("小写字母的个数为:%d",alp_a);
    printf("大写字母的个数为:%d",alp_A);
    printf("数字的个数为:%d",num);
    printf("其他的个数为:%d",oth);
}
编译环境:code::blocks
提示错误:
\num_aip\num_alp.c|2|warning: return type of 'main' is not 'int'|
\num_aip\num_alp.c||In function 'main':|
\num_aip\num_alp.c|17|error: case label does not reduce to an integer constant|
\num_aip\num_alp.c|20|error: case label does not reduce to an integer constant|
\num_aip\num_alp.c|23|error: case label does not reduce to an integer constant|
||=== Build finished: 3 errors, 1 warnings ===|

搜索更多相关主题的帖子: 统计 
2011-06-12 23:24
bccn_2012
Rank: 6Rank: 6
等 级:侠之大者
帖 子:158
专家分:447
注 册:2011-5-14
收藏
得分:20 
程序代码:
#include <stdio.h>


 void main()

 {
     int num,alp_a,alp_A,oth; 
     char a;
     num=0;
     alp_a=0;
     alp_A=0;
     oth=0;
     printf("本程序负责统计输入的字符的类型\n");
     printf("类型有大写字母、小写字母、数字、其他字符\n");
     printf("请输入字符\n");        //按ESC是不能退出的     
     a=getchar();
     while(a!='\n')
     {
         if(a>='a' && a<='z') alp_a ++;
         else if(a>='A' && a<='Z') alp_A ++;
         else if(a>='0' && a<='9') num ++;
         else oth ++;
          a=getchar();
         /*switch (a)
         {
             case a>='a' && a<='z':      //case 只能判断字符和数字常量 不能判断表达式的值
                 alp_a ++;
                 break;

 
            case a>='A' && a<='Z':
                 alp_A ++;
                 break;
             case a>='0' && a<='9':
                 num ++;
                 break;
             default:
                 oth ++;
                 break;
         }*/
         //printf("请输入下一个字符:\n");
     }
     printf("统计结果如下:\n");
     printf("小写字母的个数为:%d\n",alp_a);
     printf("大写字母的个数为:%d\n",alp_A);
     printf("数字的个数为:%d\n",num);
     printf("其他的个数为:%d\n",oth);

 }

 
2011-06-12 23:54
ansic
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:恍惚窈冥
等 级:城市猎人
帖 子:1543
专家分:5367
注 册:2011-2-15
收藏
得分:10 
程序主要部分:
程序代码:
        int dx=0,xx=0,sz=0,qt=0;
        char ch;
        do {
                ch=getchar();
                if(ch>='a'&&ch<='z') xx++;
                else if(ch>='A'&&ch<='Z') dx++;
                else if(ch>='0'&&ch<='9') sz++;
                else qt++;
        }while(ch!='\n');

善人者,不善人之师;不善人者,善人之资。不贵其师,不爱其资,虽智大迷。
2011-06-12 23:56
雾雨淼淼
Rank: 2
来 自:甘肃金昌
等 级:论坛游民
帖 子:85
专家分:89
注 册:2010-8-17
收藏
得分:0 
明白了,非常感谢
2011-06-13 23:04
快速回复:统计字符,请大家帮我找找错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031647 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved