T
Tom
Guys,
On page 97 of K&R (2nd ed) there is a function called getint().
I won't paste it here because I assume most people can look it up, but
if you want me to I will.
The 6th line of the body of the function is:
ungetch(c) /* it's not a number */
I don't understand this. This pushes the character (c) back to input
if it is not a number. But this creates an infinite cycle of finding a
non-number, pushing it back to input, reading the next character on
the input, finding it to be the same non-digit character and pushing
it back again.
Shouldn't this line be omitted, so that we can just skip to 'return
0', so that we can progress to the next character in the input?
As the function is written, if we hit a non-digit in the input it will
just get stuck there until the algorithm hits the MAX limit.
Am I missing something or is this a mistake?
Thanks,
Tom
On page 97 of K&R (2nd ed) there is a function called getint().
I won't paste it here because I assume most people can look it up, but
if you want me to I will.
The 6th line of the body of the function is:
ungetch(c) /* it's not a number */
I don't understand this. This pushes the character (c) back to input
if it is not a number. But this creates an infinite cycle of finding a
non-number, pushing it back to input, reading the next character on
the input, finding it to be the same non-digit character and pushing
it back again.
Shouldn't this line be omitted, so that we can just skip to 'return
0', so that we can progress to the next character in the input?
As the function is written, if we hit a non-digit in the input it will
just get stuck there until the algorithm hits the MAX limit.
Am I missing something or is this a mistake?
Thanks,
Tom