荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: huhaiming (一生只爱她), 信区: Program
标  题: Re: 统计字符的一段程序,为什么不行?
发信站: 荔园晨风BBS站 (Mon Dec  1 21:05:29 2003), 站内信件

判断条件错了

说说我的写法吧
#include <stdio.h>
#include <ctype.h>

int main()
{
        char ch;
        int letter = 0,space =0 ,digit = 0,other = 0;

        printf("please input a line character:\n");

        while( scanf("%c",&ch) == 1 && ch != 10 )
        {
                if( isalpha(ch) )               letter++;
                else if( isdigit(ch) )          digit++;
                else if(ch == ' ' )             space++;
                else                            other++;
        }

    printf("letter=%d,space=%d,digit=%d,other=%d\n",letter,space,digit,other);

        return 0;
}
【 在 kyle (风流多少情多少) 的大作中提到: 】
: #include <stdio.h>
: main()
: { char c;
:   int letter=0,space=0,digit=0,other=0;
:   printf("please input a line character:\n");
:   while((c=getchar())!='\n');
:       {if(c>='a'&& c<='z'||c>'A'&& c<='Z')
:          letter++;
:        else if(c==' ')
:          space++;
:        else if(c>='0'&& c<='9')
:          digit++;
:        else
:          other++;
:       }
:    printf("letter=%d,space=%d,digit=%d,other=%d\n",letter,space,digit,other);
:    }


--

菩提本无树,明镜亦非台

本来无一物,何处惹尘埃

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.26.200]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店