Re: need for an extra variable.
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Tue, 31 Oct 2006 12:15:17 +0000
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)
.
- References:
- need for an extra variable.
- From: chandanlinster
- need for an extra variable.
- Prev by Date: string search?
- Next by Date: Re: I have a problem in my study
- Previous by thread: Re: need for an extra variable.
- Next by thread: Re: need for an extra variable.
- Index(es):