This problem is from K&R p. 20: Write a program to count blanks, tabs, and newlines.
Here's my attempt:
#include <stdio.h>
int main()
{
int character, whitespace = 0;
printf("Enter some text, and press Ctrl-d when you're done.\n\n");
while((character = getchar() != EOF) {
if(character == (' ' || '\n' || '\t')) {
++whitespace;
}
}
printf("\nYour text contains %d spaces, tabs, and lines.\n", whitespace);
return 0;
}
The program doesn't work. It always gives the answer 0 no matter how many spaces, tabs, and newlines the user text contains. Can anyone see the problem? There's one other strange thing: I have to press Ctrl-d twice for it to register. I have no idea why. Thanks!