Image

Programs - C Language - File Handling

Program:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(int argc,char *argv[]){
 FILE *source,*dest;
int c;

if(argc!=3) {
  printf("wrong number of argument\n");
  exit(1);
 }

if(source=fopen(argv[1],"r"))==NULL){
  printf("can't open source file\n");
  exit(1);
 }

if((dest=fopen(argv[2],"w"))==NULL){
  printf("cant open destination file");
  exit(1);
 }

while(c=fgetc(source))!=EOF)
  fputc(c,dest);

 fclose(source);
 fclose(dest);

 getch();
}