Re: contest questions

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message -----
From: "C. K. Lester" <cklester at yahoo.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: contest questions


>
> Robert Craig wrote:
> >
> > > For the contests, what is "standard input?"
> >
> > It's file number 0.
> > i.e. your program should read from file 0,
> > using for example, getc(0) or gets(0),
>
> Don't I have to do a
>
>   fn = open(thefile,"r")
>
> and then use fn for input:
>
>   nextLine = gets(fn)
>
> Why would I hardcode the '0'?
>
>   nextLine = gets(0)
>
By agreed convention, Unix derived operating systems (ie MS-Dos (via CP/M),
Linux and Windows (via MS-Dos)) use the concept of file handles that are
returned when opening files. These are typically indexes into a system table
that holds all the file's runtime metadata. The first three values 0, 1, 2
have been reserved for stdin (by default the keyboard), stdout (by default
the screen), and stderr (by default the screen). These are not Euphoria
conventions, but derive from Unix conventions.

The shell command processor for these operating systems usually support
redirection of the std file handles using the '<' and '>' syntax. Thus a
command line:

    myprog >file.dat

usually indicates that the program is designed to write to the screen (using
stdout) but the user has decided to redirect the output to a file called
"file.dat". The use of redirection is very useful as it means that many
programs (utilities mainly) can just assume that input comes from stdin and
output goes to stdout and then let the user decide at runtime what actual
files to use via redirection. The programmer then doesn't have to concern
themselves with opening and closing files etc...


> > It should be possible to run your program
> > from a command line, such as:
> >
> >         ex yourprog < english.txt > coded.txt
>
> Can I allow the user to just do this:
>
>   ex yourprog words
>
> and then yourprog loads up words & ".txt" or something?
>
> > Without the "<" on the command-line
> > it would be, but I'm not going to test it that way.
>
> So, "<" becomes standard input?!
>
> Like when I do
>
>   nextLine = gets(0)
>
> it's going to read from the file after the "<"?
>
> OIC. So the first file is file 0 and the second is file 1...?

Yes. This is supposed to be supported in the commandline processing that the
programs/shell does before your program gets to run.
---------
Derek.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu