462 Programming and Data Structures
fp=fopen(argo{l],nr");
if(fp = N U L L )
I
printf ( File N ot Found");
exit(l);
)
*p=fopen(argv[2],”r");
if (s p = N U L L )
I
fcloseallO;
rename(argv[l],argv[2]);
I
else
printf ("Duplicate file name or file is in use." );
return 0;
I
Explanation In the above program the main () receives two file names. Existence of old file is
checked through read mode. If the file does not exist the program terminates. On the other hand if
the second file exists the rename operation can not be done. If the file pointer of second file contains
N
ULL value then only rename operation is performed otherwise program terminates with
appropriate error message.
13,11 ENVIRONMENT VARIABLES
Environment variables provide different system settings/ path related to operating system. These
variables are available in both MS-DOS and UNIX operating system. The output depends upon the
operating system. The following program displays the output related to MS - DOS.
13.42 Write a program to use environment variable and display the various settings.
4 include <stdio.h>
# Include <conio.h>
vo id m ain(in t arge, char * a r g v [] , char *en v[] )
{
in t i ;
c lr s c r ( ) i
for (i*Opnvlill*N U LL;++i)
I
printf ("% sn"^nv{i]);
I
..................Content has been hidden....................

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