| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 716 人关注过本帖
标题:超级菜鸟向大家求助!!
只看楼主 加入收藏
与它为舞
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-4-7
收藏
 问题点数:0 回复次数:8 
超级菜鸟向大家求助!!

有这么一个题
它是要求:输入一行字符,分别统计其中英文字母,空格,数字和其他字符的个数(它是要求用while,do while嵌套来做),请大家帮帮忙,谢谢.
下面这个是我编的,没做完,因为做一半就发现不对,就没往下编了,请大家多多鞭苔.





#include<stdio.h>
void main()
{
int x;
char i,ans;
ans='y';
do{
x=0;
printf("请输入一行字符: ");
fflush(stdin); //清空键盘输入缓冲区//
do
{
i=getchar();
x++;
}while (i!='\n');
printf("\n 字符的个数为: %d",--x);
if ((i>='a'||i<='z')||(i>='A'||i<='Z'))
{
printf("\n 字母的个数为: %d",x);
}
printf("\n 是否需要输入更多的字符(Y/N)? ");
ans=getchar();
}while (ans=='Y'||ans=='y');
}

搜索更多相关主题的帖子: ans 超级 字符 
2007-04-14 19:05
与它为舞
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-4-7
收藏
得分:0 

郁闷中,弄了半天,还是不对啊~
希望懂的朋友们,帮忙看看~指点指点


#include<stdio.h>
void main()
{
int x,z,q;
char i,ans;
ans='y';
do{
x=0;
printf("请输入一行字符: ");
fflush(stdin); //清空键盘输入缓冲区//
do
{
i=getchar();
x++;
}while (i!='\n');
printf("\n 字符的个数为: %d",--x);
if ((i>='0'||i<='9')||(i>='a'||i<='z')||(i>='A'||i<='Z'))
{
printf("\n 数字的个数为: %d",z);
z++;
}
{
printf("\n 字母的个数为: %d",q);
q++;
}

printf("\n 是否需要输入更多的字符(Y/N)? ");
ans=getchar();
}while (ans=='Y'||ans=='y');

}

2007-04-14 23:12
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
输入的字符你没有保存.同时你也没有把处理字符放在循环里.

倚天照海花无数,流水高山心自知。
2007-04-14 23:21
与它为舞
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-4-7
收藏
得分:0 
回复:(QQ0001000)#include

#include<stdio.h>
void main()
{char c;
 int letters=0,space=0,digit=0,others=0;
 printf("please input some characters\n");
 while((c=getchar())!='\n')
 {
 if(c>='a'&&c<='z'||c>='A'&&c<='Z')
  letters++;
 else if(c==' ')
  space++;
   else if(c>='0'&&c<='9')
       digit++;
     else
       others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
}



你这个等距离运行起来有错啊?
c(4) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(4) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(5) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(5) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(6) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(6) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(7) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(7) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(8) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(8) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(9) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(9) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(9) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(9) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(10) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(10) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(11) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(11) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(11) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(11) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(12) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(12) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(12) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(12) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(12) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(12) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(13) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(14) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
C:\Documents and Settings\Administrator\桌面\zzz.c(15) : error C2018: unknown character '0xa1'
执行 cl.exe 时出错.

zzz.obj - 1 error(s), 0 warning(s)

2007-04-15 09:08
冰天雪
Rank: 1
等 级:新手上路
威 望:1
帖 子:331
专家分:0
注 册:2007-2-27
收藏
得分:0 
这个程序在经典编程中的第17例就是
2007-04-15 09:31
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
应该把标点符号该成英文的,他的思想是对的啊

学习需要安静。。海盗要重新来过。。
2007-04-15 09:34
与它为舞
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-4-7
收藏
得分:0 
经典编程?在哪能找到?
把标点符号换成英文的也不对啊!
2007-04-15 09:41
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
提示这样的错误应该是输入法不对,可能是什么地方的输入字符错了,要不你重输一遍啊,我改了一会,错误在减少,你改一改试试.

学习需要安静。。海盗要重新来过。。
2007-04-15 10:16
快速回复:超级菜鸟向大家求助!!
数据加载中...
 
   



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

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