C program to copy file using command line arguments.

#include<stdio.h>
#include<conio.h>
int main(int argc, char* argv[]){
char ch;
FILE *fp1,*fp2;
if(argc!=3){
printf("The number of arguments are not sufficient\n");
getch();
exit(0);
}
printf("copying file....\n");
fp1=fopen(argv[1],"r+");
fp2=fopen(argv[2],"w+");
if(fp1==NULL || fp2==NULL){
printf("copy failed\n");
fcloseall();
getch();
exit(0);
}
while(feof(fp1)){
ch=fgetc(fp1);
fputc(ch,fp2);
}
printf("file copied successfully\n");
fcloseall();
getch();
}

No comments:

Post a Comment