Following the book The C Programming Language by Kernighan and Ritchie, I am trying do the following exercise:
Exercise 1-12 Write a program that prints its input one word per line.
This is my code:
main(){
int b;
while( (b=getchar()) != EOF){
if(b != ' ' || b != '\t' || b != '\n')
putchar(b);
if(b == ' ' || b == '\t' || b == '\n')
printf("\n");
}
}
My problem is that pressing ENTER to get a newline executes the code in stead of just giving me a newline in the console.
Should not just an EOF do this? Otherwise, the program works just fine.
Edit: This is not, as far as I understand, a duplicate of Why non-equality check of one variable against many values always returns true? Although I should have used "&&" and not "||", the problem remains. When I press ENTER in the console, the program is executed in stead of giving me a newline. Please correct me if I am wrong.