还是2次输出问题,好郁闷
用getchar()编写程序,从键盘读入字符,知道遇上#停止,计算a, b, c出现次数#include "stdio.h"
int main(void)
{
int a ,b ,c ;
int d;
a = b = c = 0;
while((d = getchar()) != '#'){
if (d == 'a')
++a;
if (d == 'b')
++b;
if (d =='c')
++c;
putchar(d);
printf("\na is printed %d, b is printed %d, c is printf %d.\n",a, b, c);
}
return 0;
}
如果输入d,就显示
d
a is printed 0, b is printed 0, c is printed 0.
a is printed 0, b is printed 0, c is printed 0.
不解中