有这么一个题
它是要求:输入一行字符,分别统计其中英文字母,空格,数字和其他字符的个数(它是要求用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');
}
----------------解决方案--------------------------------------------------------
郁闷中,弄了半天,还是不对啊~
希望懂的朋友们,帮忙看看~指点指点
#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');
}
----------------解决方案--------------------------------------------------------
输入的字符你没有保存.同时你也没有把处理字符放在循环里.
----------------解决方案--------------------------------------------------------
#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)
----------------解决方案--------------------------------------------------------
这个程序在经典编程中的第17例就是
----------------解决方案--------------------------------------------------------
应该把标点符号该成英文的,他的思想是对的啊
----------------解决方案--------------------------------------------------------
经典编程?在哪能找到?
把标点符号换成英文的也不对啊!
----------------解决方案--------------------------------------------------------
提示这样的错误应该是输入法不对,可能是什么地方的输入字符错了,要不你重输一遍啊,我改了一会,错误在减少,你改一改试试.
----------------解决方案--------------------------------------------------------