Re: getc can return EOF, but ungetc can't sent it back... why?
From: TTroy (tinesan_at_gmail.com)
Date: 03/12/05
- Next message: linzhenhua1205_at_163.com: "How to parse a string like C program parse the command line string?"
- Previous message: Mark F. Haigh: "Re: Please help optimize (and standarize) this code..."
- In reply to: Lawrence Kirby: "Re: getc can return EOF, but ungetc can't sent it back... why?"
- Next in thread: lawrence.jones_at_ugs.com: "Re: getc can return EOF, but ungetc can't sent it back... why?"
- Reply: lawrence.jones_at_ugs.com: "Re: getc can return EOF, but ungetc can't sent it back... why?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Mar 2005 21:22:42 -0800
Lawrence Kirby wrote:
> On Wed, 09 Mar 2005 13:01:12 -0800, TTroy wrote:
>
> > Hello C programmers,
> >
> > Can someone tell me why ungetc can't sent back EOF, but it's sister
> > function getc has no trouble sending it to us?
>
> EOF is not a characer value, it is a failure indicator. When getc()
> returns EOF it is saying "I couldn't get a character for you". The
reason
> for that might be that the stream is at end-of-file (which you can
detect
> with feof()) or maybe some error occurred on the strean (which you
can
> detect with ferror()).
>
> > For a file, this might
> > not make a difference, but for an interactive terminal, it is
probably
> > nice to push EOF back (because to user doesn't want to provide an
EOF
> > twice).
>
> Since EOF isn't a character it makes little sense to "push it back".
> If you pass the value of EOF to ungetc() it fails and does nothing to
the
> stream. So if the stream was at end-of-file it will still be after
such an
> ungetc() call, and if the stream has an error condition flagged it
will
> still do so after such a call. I'm not sure how this differs from
what you
> are requesting.
>
My question is the use of EOF specifically as an EXIT flag in programs
coming from user input from keyboard. Thus a user provides EOF to
signal that the program should be ended. Unlike EOF for end of file
indication, this user provided EOF is momentary, and will be missed if
the part of the program that reacts to EOF doesn't read it (so another
part reads it). I just wanted a way where the -other part- could push
back anything even EOF so the part that runs the whole show will see
the EOF and end the program.
I realize the valid points you guys have made and now I'm satisified
knowing that what I wanted really isn't possible (I hate thinking -
there must be a way to do this but I can't figure it out- but now I'm
thinking - this is impossible so shut up brain!!!-).
thanks,
Tinesan Troy, B.Eng (Mech)
tinesan@gmail.com
- Next message: linzhenhua1205_at_163.com: "How to parse a string like C program parse the command line string?"
- Previous message: Mark F. Haigh: "Re: Please help optimize (and standarize) this code..."
- In reply to: Lawrence Kirby: "Re: getc can return EOF, but ungetc can't sent it back... why?"
- Next in thread: lawrence.jones_at_ugs.com: "Re: getc can return EOF, but ungetc can't sent it back... why?"
- Reply: lawrence.jones_at_ugs.com: "Re: getc can return EOF, but ungetc can't sent it back... why?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|