Re: need for an extra variable.



chandanlinster said:

hello everybody,
consider the following code snippet (from K & R, pg78)

while ((s[0] = c = getch()) == ' ' || c == '\t')
;

my question is, why would we need the variable 'c'.
We could easily write it as,

while ((s[0] = getch()) == ' ' || s[0] == '\t')
;

c is used several times later in that function, and this includes the value
assigned to it here. Rewriting it without c could prove an interesting
exercise. I suggest you do so, testing your changes thoroughly. Then look
at the resulting code, and compare it to K&R's original. If you think your
replacement is clearer (and if it works identically), then feel free to use
it instead.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.