注册 登录
编程论坛 C++教室

请大家帮忙看一个程序,有点小问题不懂!

luguolian 发布于 2013-08-11 08:35, 456 次点击
#include <stdio.h>
int count(char ch)
{ if(ch>='A'&&ch<='Z'||ch>='a'&&ch<='z') return 1;
  if(ch>='0'&&ch<='9') return 2;
  else return 0;
}
void main()
{ int i,cc=0,num=0,other=0;
  char  ch;
  scanf("%c",&ch);
  for(i=0;ch!='\n';i++)
  { if(count(ch)==1) cc++;
    else
      if(count(ch)==2) num++;
      else other++;
    scanf("%c",&ch);
  }
   printf("charsum=%d,cc=%d,num=%d,other=%d\n",i,cc,num,other);
}
这个程序是判断输入的一个字符串中有多少个 数字 字母 和其他字符。
第二个scanf的意义我不懂,请指教一下。
1 回复
#2
Mhugh2013-08-11 09:51
都是获取输入的字符,因为不可能只用一个scanf就获取了全部的,需要在循环中一个一个的判断输入的字符
1