in reply to writing to stdin

The code already offered is excellent, but I'd like to address the conceptual bug in your understanding. On a UN!X machine, i.e. FreeBSD, Linux, Solaris, et al, STDIN and STDOUT are both connected to the console unless they are connected to pipes (or otherwise redirected). STDIN accepts what you type (which is also echoed automatically to STDOUT), and STDOUT prints what your program spits out. In other words, to put stuff on your console, you print 'stuff';, which can also be written as print STDOUT 'stuff';.

HTH :D

Replies are listed 'Best First'.
Re^2: writing to stdin
by ambs (Pilgrim) on Mar 28, 2005 at 14:12 UTC
    If you used to program with lex or flex you would notice that the question is not so weird. In fact, it is common to use 'unput' to put characters back in the input buffer (which in fact can be from stdin).

    Ok, I know flex does not push it into stdin, but it gives you that idea.

    Cheers

    Alberto Simões

      Aye, but we be dealin' wit a newbie here, to be sure. You be absolutely correct in ta wunderful complexity of te entire UN!X worlt, but let's not be confusin te poor bairn right from t'start. :D