Reputation: 700
I have this code
whitespaces is a type int, so I can use the getchar function
do
{
...code...
whitespaces=getchar();}
while ( whitespaces != (EOF) || whitespaces!='\n');
but it doesnt exit the loop when i hit CTRL+Z (i am using windows 7)
what am I doing wrong?
EDIT : thank you, all of you...! very helpful
Upvotes: 0
Views: 558
Reputation: 1359
Try changing the ||
to &&
. Right now, if whitespaces
is equal to EOF
, it's not a newline, so the while condition is always true. This is presumably not what you want.
Upvotes: 1
Reputation: 3586
Your condition is incorrect:
while ( whitespaces != (EOF) && whitespaces!='\n');
A \n will automatically be different than EOF and vice-versa.
Upvotes: 1