Files 463
OUTPUT
TMP=C:WINDOWSTEMP
TEMP=C:WINDOWSTEMP
PROMPT=$p$g
winbootdir=C:WINDOWS
COMSPEC=C:WIN DOWSNCOMMAND.COM
PATH=C:WINDOWS;C:WINDOWSCOMMAND;C:JDK1.2.1BIN;0JDKU2.1;
CMDLINE=WIN
windir=C:WINDOWS
13.12 I/O RE DIRECTION
Consider the dos command d i r > a b c , execute it at dos prompt. Here, d i r is the internal dos
command and abc is the name of the file. Here, instead of displaying list of files and directories on
the screen, it is redirected in a text file abc i.e. the files and directories would be possible to see in
abc file. For this use type abc command at dos prompt.
From the above example the reader can understand that the output of command can be redirected to
another file. Using redirection the output of the program instead of displaying on the screen is stored
on the disk in the form of file. With this we can avoid creating separate functions for writing files to the
disk or to the printer. Thus, this is an advantage and is a convenient approach for writing files to the
disk. Using this redirection concept both read and writes operations are possible.
13.43 Write a program to read character from keyboard till user presses enter.
# in clu d e < std io .h >
# in clud e <conio.h>
void mainO
c
char c;
while ((c=g etc(std in))l= fn f)
putdCrStdout);
I
123456789
Explanation On compiling this program we would get an executable file r e a d . exe. Execute this
program on the dos prompt as given below.
C> rea d .e xe > in p u t.tx t
Now, whatever data is inputted is redirected to text file inpu t. txt. To confirm, type the file using type
command. The output would be
123456789
464 Programming and Data Structures
The redir ec tion operator ' > ' transfers any output proposed for screen to the file followed by the
operator.
It is optional to input data in the program. We can also redirect output of the program generated by
itself to the text file. The above program illustrates this point.
13.44 Write a program to display A to Z characters.
# include <stdio.h>
# include <conio.h>
void main()
{
int a;
clrscr();
for (a=*65;a<91;a++)
printf("t%ct",a);
printf ("n ");
I
OUTPUT
A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y
I
Explanation After compilation we get the exe file. Execute it at dos prompt as given below.
C> ALPHA.EXE > ABC.TXT
After execution, the output generated by the program is directed to file abc. txt. It is also possible to
send the output to printer. For this follow the following syntax.
C> ALPHA.EXE > PRN
We can also redirect the input to the program from a file. Instead of writing with the keyboard a
complete file can be transferred. The program below given explains this point.
C> read.exe < abc.txt
This command display output
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.27.251