Hello, This code seems fine to me, the problem is when I enter a text and push enter nothing is happening, seems like getchar is not working at all.
What am I missing??
#include <stdio.h>
int main(void){
int NumberWords = 0, NumberLetters = 0;
float Average;
char ch;
printf("Enter a sentence: ");
while ((ch = getchar()) != '\n'){
NumberWords++;
while ((ch = getchar()) != ' '){
NumberLetters++;}
}
Average = NumberWords/NumberLetters;
printf(" Average word length: %1.f\n", Average);
return 0;
}