460 Programming and Data Structures
C:\TC> C.EXE HELP ME
In the above example c . exe is an executable file and "HELP ME " are taken as arguments. The total
number of arguments including the program file name are 3.
13.10 APPLICATION OF COMMAND LINE ARGUMENTS
The following programs can be used on command prompt similar to that of DOS commands.
1. Type
13.39 Write a program to read any file from command prompt. Use command line arguments,
(Save this program as read.c)
# include <stdio.h>
# include <conio.h>
# include <process.h>
main( in t argc, char * a r g v [])
{
VXLB *fp;
in t ch;
f p»fiopen (argv[1 ],"r" ) ;
i f (fpNOLL)
{
printf ( “Can not open file");
exit(0);
I
while (!feof(fp))
I
ch=fgetcifp);
printf ( “%c",ch);
I
fcloseifp);
return 0;
I
Explanation The above program after getting its exe file, will run similarly as type command of
DOS. On the command prompt one should write first exe file name and file name is to be read. The
contents of file will be displayed on the screen.
2. Del
13.40 Write a program using command line argument to perform the task of DEL command
of DOS. ( Save this program as cutc)
§ include <stdio.h>
# include <conio.h>

Get Programming and Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.