|
发表于 2013-8-21 17:22:19
|
显示全部楼层
本帖最后由 liufei_vip 于 2013-8-21 17:51 编辑
- #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!='\n';) //这里改了
- {
-
- 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);
- }
复制代码 这是修改后的代码及结果,不知道是不是你要的。
|
|