#include<stdio.h>
#include<stdbool.h>
#include<ctype.h>
int main()
{
bool inword = false;
float count;
int word, letter;
char ch;
word = letter = 0;
printf("Please enter the some words( EOF to quit):\n");
while ((ch = getchar()) != EOF)
{
if (ispunct(ch))
continue;
if (isalpha(ch))
letter++;
if (!isspace(ch) && !inword)
{
inword = true;
word++;
}
if (isspace(ch) && inword)
inword = false;
}
count = (float)letter / word;
printf("Total words:%d\n", word);
printf("Total letter:%d\n", letter);
printf("Average letter of the word:%g\n", count);
return 0;
}
想问一下,定义bool inword为false,但是当getchar()读取到到第一个字母的时候,经过第三个if的时候,为什么判断为真