| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4720 人关注过本帖
标题:输入一行文字,找出其中大写字母、小写字母、空格、数字及其他字符各有多少 ...
只看楼主 加入收藏
sange
Rank: 2
等 级:论坛游民
帖 子:12
专家分:26
注 册:2011-3-8
结帖率:33.33%
收藏
已结贴  问题点数:10 回复次数:5 
输入一行文字,找出其中大写字母、小写字母、空格、数字及其他字符各有多少。不知道为什么出错
输入一行文字,找出其中大写字母、小写字母、空格、数字及其他字符各有多少。请路过的高手帮我看看,谢谢
#include"stdio.h"
#include"string.h"
int main()
{
    int upper=0,lower=0,space=0,digit=0,other=0,i=0;

    char *p,s[20];
    printf("input string:");

    while(  (s[i]=getchar())!='\n')i++;
    p=s;
    while(*p!='\n')

    {
        if(  ('A'<=*p)&&(*p<='Z')  )
            ++upper;
        else if( ('a'<='*p')&&(*p<='z')  )
            ++lower;
    else if( *p=='')
        ++space;
        else if( (*p<='9')&&(*p>='0') )
            ++digit;
        else
            ++other;
        p++;
    }
    printf("upper case:%d lower case :%d",upper,lower);
    printf(" digit:%d other:%d\n",digit,other);
    return 0;

}

Compiling...
1.cpp
F:\test\88\1.cpp(20) : error C2137: empty character constant
执行 cl.exe 时出错.
搜索更多相关主题的帖子: 字母 include 
2011-04-10 13:27
hjywyj
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:1114
专家分:2611
注 册:2010-4-14
收藏
得分:3 
int x=0,i=0,j=0,k=0,m=0,n=0;
char a[30];
while((a[x]=getchar())!='\n')
{if(a[x]>='A'&&a[x]<='Z')
i++;
else if(a[x]>='a'&&a[x]<='z')
j++;
else if(a[x]>='0'&&a[x]<='9')
k++;
else if(a[x]==' ')
m++;
else n++;
x++;}
printf("大写:%d,小写:%d,数字:%d,空格:%d,其他:%d",i,j,k,m,n);
2011-04-10 13:53
hjywyj
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:1114
专家分:2611
注 册:2010-4-14
收藏
得分:0 
else if( ('a'<='*p')&&(*p<='z')应为:else if( ('a'<=*p)&&(*p<='z')
else if( *p=='')应为else if( *p==' ')(少了个空格)
2011-04-10 13:55
sange
Rank: 2
等 级:论坛游民
帖 子:12
专家分:26
注 册:2011-3-8
收藏
得分:0 
谢谢,hjywyj
2011-04-10 13:58
张春平
Rank: 3Rank: 3
来 自:北城
等 级:论坛游侠
帖 子:48
专家分:124
注 册:2010-12-2
收藏
得分:3 
else if( *p=='')单引号里面少了个空格

2011-04-10 20:20
hnuhsg1226
Rank: 9Rank: 9Rank: 9
来 自:中国
等 级:蜘蛛侠
威 望:2
帖 子:314
专家分:1314
注 册:2011-3-27
收藏
得分:3 
这里调用ctype函数库里的几个函数比较方便
int islower(char ch);判断小写字母
int isupper(char ch);判断大写字母
int isdigit(char ch);判断数字

我的地盘
2011-04-10 22:07
快速回复:输入一行文字,找出其中大写字母、小写字母、空格、数字及其他字符各有 ...
数据加载中...
 
   



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

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