Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: scanf dilemma for beginner

Thread Tools

Re: scanf dilemma for beginner

The Real OS/2 Guy
Posts: n/a
On Sun, 31 Aug 2003 19:20:49 UTC, Irrwahn Grausewitz
<(E-Mail Removed)> wrote:

> "The Real OS/2 Guy" <(E-Mail Removed)> wrote in
> <wmzsGguTDN6N-pn2-nLfghd2yuL32@moon>:
> I agree with most of what you've said in your reply, but
> the OP's problem was with interactive user input, not
> stream filters,

Even that is a stream filter. The source is stdin, the destination
stdout. Typical filter:
- read something from stdin, write something to stdout, write errors
to stderr
C knows nothing about devices, so the keyboard comes as stdin and the
typewriter/high res screen as stdout.
C knows nothing about interactive I/O. But it knows perfectly of

so there are no performance issues - the
> user is the bottleneck here, not buffer manipulation. And
> it's somewhat unlikely that someone will enter data
> manually in a manner that realloc() will fail.

realloc can only reserve memory it has. realloc fails quickly when the
system is out of (virtual) memory.

Time is always an issue, even when the user types slowly - the work
the application has to do on his/her input is always a boddlenec
because the user awaits the result of his input immediately. And even
when you'd designed a program for interactive usage it can be run in
batch mode whereas the input is a 2 GB file redirected to stdout
(cat file | app 2>app.log -c app.config | tee file2)


eComStation 1.1 Deutsch Beta ist verügbar
Reply With Quote
The Real OS/2 Guy
Posts: n/a
On Mon, 1 Sep 2003 13:02:07 UTC, LibraryUser
<(E-Mail Removed)> wrote:

> The Real OS/2 Guy wrote:
> > <(E-Mail Removed)> wrote:
> >

> ... snip ...
> > >
> > > Sometimes it's good to have more than one character lookahead
> > > when parsing input. In some cases it's ok to not throw away
> > > remaining input and re-sync in order to provide some sort of
> > > error recovery.

> >
> > Correct -but for that it's quite easy to write a wrapper around
> > getc and ungetc to exted the ability of ungetc to put more chars
> > back to stream.

> Except that, having done that, most of the standard library (and
> maybe much more) does not use those wrappers, leading to
> confusion. You find you have ungetted several characters, and
> then call, say, scanf(), which takes an entirely different view
> of the world, and leaves unconnected things in your pseudo input
> stream.
> So, if you do such things, for sanity you need to replace
> anything and everything to do with char i/o.

That it's. You use getc() and nothing else to read from that stream.
Ever you gets up mixing differen function in input you'll end up with
an uncontrolled stream! Being consistent is the maxim.

There is nothing that hinders you to use fscans() on other, trusted
streams where reading char by char on the untrusted stream.


eComStation 1.1 Deutsch Beta ist verügbar
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 18 05-02-2006 10:53 AM
scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc. =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 185 04-03-2006 02:49 PM
Nikon RAW Beginner's Question / Dilemma Xtx99 Digital Photography 13 01-13-2005 02:25 PM
Re: scanf dilemma for beginner Greg P. C Programming 7 08-30-2003 03:05 PM
Re: scanf dilemma for beginner Ian Roddis C Programming 0 08-29-2003 01:28 AM