Hints




Document: Software Engineering 1: Course Notes

next Session 9: Week 17/18: Projectiles
up Session 8: Week 15/16: Encryption
previous Session 8: Week 15/16: Encryption

Hints

 

Perhaps the simplest way of arranging for your program to take its input from a file, and/or route its output to a file, is to use so-called command line redirection.

To do this your program must already have been compiled successfully, resulting in the creation of an executable version of it. If your source file were called foobar.c, the executable version would be in a file called foobar.exe. The executable version must be run from the MS-DOS command line interpreter application (and not from within the Turbo-C++ IDE) in order to use redirection. So you should start up an MS-DOS Window by double clicking on the relevant icon in Program Manager.

Within this window you will first need to set the "current" drive and directory to where you have stored the executable program. This will normally be the directory \swe1_tc on drive D:, so issue the following commands:

    C:\WINDOWS> d:
    D:\> cd \swe1_tc
    D:\SWE1_TC>

Now execute your program, with a command something like this:

    D:\SWE1_TC> foobar <in.txt >out.txt

The < serves as the "input redirection" character in an MS-DOS command line. The effect is that the input for foobar will no longer be taken from the keyboard, but from this file instead. Similarly, the > character in an MS-DOS command provides for output redirection, to direct output to a file instead of the screen. With any given command invocation you can use input redirection only, or output redirection only, or both together.

Note that if you change your program you must rebuild it it again, from within the IDE, before trying to rerun it in the MS-DOS application.

To close down the MS-DOS application, give the command exit thus:

    D:\SWE1_TC> exit




Document: Software Engineering 1: Course Notes

next Session 9: Week 17/18: Projectiles
up Session 8: Week 15/16: Encryption
previous Session 8: Week 15/16: Encryption



McMullin@ugmail.eeng.dcu.ie
Wed Mar 15 10:20:49 GMT 1995