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

有这么一个题
它是要求:输入一行字符,分别统计其中英文字母,空格,数字和其他字符的个数(它是要求用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
与它为舞
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
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-4-7
收藏
得分:0 
经典编程?在哪能找到?
把标点符号换成英文的也不对啊!
2007-04-15 09:41
快速回复:超级菜鸟向大家求助!!
数据加载中...
 
   



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

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