/* program to copy one file in to another using command line arguments */
#include<stdio.h>
void main(argc, argv)
int argc;
char *argv[] ;
{
FILE *A, *B;
int c;
if(argc==1)
{
printf("\n You forgot to enter command line arguments ") ;
exit();
}
if((A=fopen(argv[1],"r"))==(FILE*)NULL)
printf(" \n Couldn't open %s for reading \n", argv[1]);
else if((B=fopen(argv[2],"w"))==(FILE*)NULL)
printf(" \n Couldn't open %s for writing \n", argv[2]);
else
{
while((c=getc(A))! =EOF)
putc(c, B);
printf("\n File has been copied \n") ;
}
}
OUTPUT :
#gcc copyfile.c
#. /a. out
You forgot to enter the command line arguments
#./a.out co1.c out.c
Couldn't open co1.c for reading
#. /a. out comm1.c out.c
File has been copied
No comments:
Post a Comment