On 08/31/2011 09:15 PM, Eric Sosman wrote:
....
The original problem statement is somewhat vague, but I think
it's pretty clear that "white space" -- any "white space" -- is to
be taken as a terminator.
Unfortunately, "white space" is left undefined. One might appeal
to isspace() from <ctype.h>, but the problem statement forbids using
it, so the position that isspace() encapsulates the definition of
"white space" is hard to sustain.
Section 6.4p3 defines both "white space" and "white-space characters",
independently of the C standard library in general, or isspace() in
particular. I don't think there's any justification for suggesting that
any alternative definition of those terms was intended. The definition
of isspace() is based upon the definition of white-space character in
6.4p3. While the instructor said "white space", I suspect he meant
"white-space characters" - I doubt that he intended that the programs
should parse and skip C-style comments.
The problem statement specified that scan_int() would approximate
scanf("%d",&x). The standard's definition of the behavior of scanf()
explicitly says that white-space characters are skipped, and cites
isspace() as defining what that means. Lacking permission to call any
standard library function other than getchar(), scan_int() cannot
emulate the locale-dependence of isspace(), but it can at least match
it's behavior in the "C" locale, and I think it's clear that the
instructor intended it to do so.
... Under the circumstances, I think
the problem-solver would be justified in considering "white space" to
be any of the characters ' ', '\t', '\n', '\v', '\r', '#', 'W', and 'q'.
I can't see any basis for including any of those last three.