|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 好人 于 2013-8-21 16:41 编辑
#include"stdio.h"
#include <conio.h>
#pragma warning (disable:4996)
void main()//软件用于分别统计输入的数字 字母及其其他字符的个数,问题估计出现在getchar的使用错误
{
int get(char a);
char b;
int c,number,abc,other;
number=abc=other=0;
b=getchar();//我的理解是getchar 用于拿出单个字符。 而
c=get(b);//我想让某函数(我也不知道是不是getchar)在输出后拿出某个字符后这个字符会消失,也就是在输入后保存的数据中消失
for(;b!='/0';)
{
if(c==0)
{
number=number+1;
}
else if(c==1)
{
abc=abc+1;
}
else
{
other=other+1;
}
b=getchar();
c=get(b);
}
printf("number is %d,abc is %d,other is %d",number,abc,other);
}
int get(char a)//get用于判断输入的字符是什么类型 数字就代表0 字母代表1 其他代表2
{
int b;
if(48>=a&&a<=57)
{
b=0;
}
else if((65<=a&&a<=90)||(97<=a&&a<=122))
{
b=1;
}
else
{
b=2;
}
return(b);
}
//今天看了函数3 在做最后一道题 ,突然有个感觉 我是不应该重新从第一集再次看起。我已经完全凌乱了!
|
|