I tested the Beej manual on IPC , and one line of code caught my attention.
On a specific page, the while loop speak.chas two conditions for checking while (gets(s), !feof(stdin)).
speak.c
while (gets(s), !feof(stdin))
So my question is how is this possible, as I saw during checking only one state most of the time.
PS: I'm a little new to this. We will be grateful for any help. Thank!
Excerpt
uses a comma operator, first it executes gets(s), then it tests !feof(stdin)what is the result of the condition.
gets(s)
!feof(stdin)
, gets, . , , , , .
while(gets(s), !feof(stdin)) { /* loop body */ }
gets(s); while(!feof(stdin)) { /* loop body */ gets(s); }
, gets .
gets
. , , , gets () - .
, : feof(file) , / , . , , ( ) EOF - (- ), , .
feof(file)
- fgets :
fgets
while (fgets(s, length_of_s, stdin)) process(s);
fgets , .
: fgets , ( gets ). , , , , (, , , , ).
gets(s) end-of-file !feof(stdin).
. gets(s), !feof(stdin), gets().
gets()
, gets(), , (, ).
@DanielFischer @trojanfoe, .
, , , , . , , .
, - , LINT (http://en.wikipedia.org/wiki/PC-Lint), , .
, @DanielFischer, gets() . fgets(), .
http://www.cplusplus.com/reference/clibrary/cstdio/fgets/
You will not regret the habit of always using fgets () instead of get, especially if it is production code.
You may also consider looking for string functions.
http://linux.die.net/man/3/snprintf
They are not part of the standard ANSI / C99 C, but if you are just developing for a specific platform, they do not allow you to crash your program or open security holes.
Good luck