Files 461
# include <process.h>
main (int argc, char *argv [])
{
FILS *fp;
i f (argc<2)
{
printf (" Insufficient Arguments");
exit(l);
}
fp=fopen(argv[l],"r");
if(fp = = N U L L)
{
printf ("File Not Found");
exit(l);
I
unlink (argvll]);
printf ("File fias been deleted ");
return 0;
I
Explanation This program performs task of DEL command of disk operating system. It deletes
only one file at a time. Create exe file of this program and execute it on the command prompt. User
should give the file name for deleting. Opening it in read mode checks the existence of file. The file will
be deleted in case it exists. In the program appropriate messages are displayed if the user makes any
mistake. Error messages are "Insufficient Arguments", "File not found" and "File has been deleted
3. Rename
13.4 Write a program using command line argument to perform the task of REN command of DOS.
(Save this program as change.c)
# include <8tdio.h>
# include cconio.h>
# include <proceas.h>
main( int argc, char * a r g v [])
{
FILS *£p,*spj
i f (argc<3 )
{
printf ("Insufficient Arguments");
exit(l);
}

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.