google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: command line arguments example
Showing posts with label command line arguments example. Show all posts
Showing posts with label command line arguments example. Show all posts

Tuesday, May 24, 2016

Write C program to copy one file in to another using command line arguments

/* 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

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...