I'm new to C. I was reading Kernigham Ritchie, and came across this example which shoes a code to count the numbers of words in the input. It was quite complex, and I was determined to write a simpler one, but my effort didn't go so well. I can't find an error in my reasoning, so please help.
I am new to C, but I have some experience in Python from my senior year of high school.
#include <stdio.h>
int main()
{
//Defining the variables
int c, nw;
nw=0;
//Creating the main loop to traverse the input
while (!(c=getchar()== EOF)) {
//Creating a condition to check whether a space or a tab has been put.
if(c==' '||c=='\t') {
++nw;
}
else{
;
}
}
printf("The number of words is ");
printf("%i", nw);
return 0;
}
The output is all right, however, it shows number of words as 0.