求大佬指点一下
本帖最后由 anhongkiusu 于 2022-2-11 18:18 编辑问题:编写程序读取输入,读到#停止,报告ei出现的次数
运行后永远显示0个ei,不知道哪有问题,求大哥们指点{:5_92:}
#include <stdio.h>
int main(void)
{
char ch;
int count = 0;
int halfpair = 0;
while ((ch = getchar()) != '#')
{
switch(ch){
case 'e':
halfpair = 1;
break;
case 'i':
if(halfpair == 1){
count ++;
halfpair =0;
}
break;
default:
halfpair = 0;
}
printf("\nTotally exist %d \'ei\' in all char!\n",count);
printf("Done!");
return 0;
}
}
#include <stdio.h>
int main(void)
{
char ch;
int count = 0;
int halfpair = 0;
while ((ch = getchar()) != '#')
{
switch (ch)
{
case 'e':
halfpair = 1;
break;
case 'i':
if (halfpair == 1)
{
count++;
halfpair = 0;
}
break;
default:
halfpair = 0;
}
}
printf("\nTotally exist %d \'ei\' in all char!\n", count);
printf("Done!");
return 0;
} ckblt 发表于 2022-2-11 18:24
哥你这个对了
可我哪里错了,我还是看不出来{:5_99:} printf("\nTotally exist %d \'ei\' in all char!\n", count);
printf("Done!");
return 0;
你的在for循环里
页:
[1]