Re: safe scanf( ) or gets

From: Irrwahn Grausewitz (irrwahn33_at_freenet.de)
Date: 12/14/03


Date: Sun, 14 Dec 2003 21:51:13 +0100


"Malcolm" <malcolm@55bank.freeserve.co.uk> wrote:
>
> "Martin Dickopp" <expires-2004-01-31@zero-based.org> wrote:
> > "Malcolm" <malcolm@55bank.freeserve.co.uk> writes:
> >
> > > The real answer is that stdin is seldom used in real programs.
> >
> > I strongly disagree. In fact, to get any /real/ work done with a
> > computer, programs which read from standard input and write to
> > standard output (AKA filter programs) are absolutely mandatory,
> > IMO.
> >
> Sound like someone knows about a world which I know nothing about.

You don't know about operating systems providing command line
interfaces? Can't believe that.

> > > and if it really needs interactivity then it uses a GUI.
> >
> > Again, if this is supposed to be general advice (it sounds as if it is,
> > sorry if I misunderstood you), I strongly disagree. Many people
> > (including myself) prefer non-GUI programs to GUI programs.
> >
> Then we realise that we are more probably dealing with an eccentric.

Nobody preferring a console interface over a GUI is an eccentric,
but someone who knows about the power of command lines.

> GUIs
> have swept the board for interactive programs.

stdin and interactive input are not equivalent. In a typical
environment input and output of a program are often redirected
to/from other sources. Remember: stdin/stdout/stderr are streams
which may be connected to a console, or a physical file. From C's
POV there's no difference, hence the rule: never use gets (for
suitable values of 'never').

> I don't know about filter programs - maybe in mainframe environments with
> non-user generated stdin.

A lot of standard command line utilities on a vast number of OSs are
filter programs. For example, you virtually can't do anything useful
on a typical *nix system without using stream filters, e.g. grep,
head, tail, sed, awk, gzip, more, cut, sort, ...

> As a games programmer I would never use nor write
> a program written in such a fashion.

Not all the world is a Wintel box. ;-)

Regards

-- 
Irrwahn Grausewitz (irrwahn33@freenet.de) 
welcome to clc : http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html 
clc faq-list   : http://www.eskimo.com/~scs/C-faq/top.html 
acllc-c++ faq  : http://www.contrib.andrew.cmu.edu/~ajo/faqs/acllc-c++.html