Re: What's the guideline for dealing with unwanted chars in input stream?
- From: "slebetman@xxxxxxxxx" <slebetman@xxxxxxxxx>
- Date: 31 Dec 2005 13:42:51 -0800
Richard Heathfield wrote:
> Chuck F. said:
>
> > Richard Heathfield wrote:
> >> lovecreatesbeauty said:
> >>
> > ... big snip ...
> > >
> >>> 19
> >>> 20 /* remove unwanted chars in input stream here now */
> >>> 21 while(getchar() != '\n'); //intended null loop body
> >>
> >> This won't work, because it will keep reading and discarding
> >> characters up to AND INCLUDING the first non-newline, which is
> >> presumably supposed to be data.
> >
> > Hunh? It will remove chars from the stream, including the '\n'.
>
> Oops. My apologies. I read it as == for some reason.
>
More accurately, the "while(getchar() != '\n');" part removes every
other character in the stream so that the following "getchar()" will
only get 'even' characters.
If "Hello world\n" is in the stream then you would only be getting "el
ol\n". In this case, because there are an odd number of chars in the
stream before the "\n", the while loop will even miss the newline.
.
- References:
- What's the guideline for dealing with unwanted chars in input stream?
- From: lovecreatesbeauty
- Re: What's the guideline for dealing with unwanted chars in input stream?
- From: Richard Heathfield
- Re: What's the guideline for dealing with unwanted chars in input stream?
- From: Chuck F.
- Re: What's the guideline for dealing with unwanted chars in input stream?
- From: Richard Heathfield
- What's the guideline for dealing with unwanted chars in input stream?
- Prev by Date: Re: Adding the ability to add functions into structures?
- Previous by thread: Re: What's the guideline for dealing with unwanted chars in input stream?
- Next by thread: An Link Error
- Index(es):
Relevant Pages
|