I was checking Beej’s guide to IPC and one line of code took my attention.
In the particular page, the while loop in speak.c has two conditions to check while (gets(s), !feof(stdin)).
So my question is how is this possible as I have seen while look testing only one condition most of the time.
PS: I am little new to these. Will be grateful for any help. Thanks!
The snippet
uses the comma operator, first it executes
gets(s), then it tests!feof(stdin), which is the result of the condition.By the way don’t use gets, it’s extremely unsafe. Be wary of sources using it, they probably aren’t good sources for learning the language.
The code
is equivalent to
just more concise as it avoids the repetition of
getsbefore the loop and in the loop body.