Program:
#include<stdio.h>
int main(){
FILE *fptr1,*fptr2;
char c;
char file_path[100];
printf("--> Enter the filename OR file path to open for reading \n");
scanf("%s", file_path);
fptr1=fopen(file_path,"r");
if(fptr1==NULL){
printf("\n->> File not Found.");
}
printf("-->>Enter file Name to create a file: \n");
scanf("%s", file_path);
fptr2=fopen(file_path,"w");
if(fptr2==NULL){
printf("\n->> File Can't Open!.");
}
c=fgetc(fptr1);
while(c != EOF){
fputc(c,fptr2);
c=fgetc(fptr1);
}
printf("\n -->>> !! File Successfully Copied. !!\n");
fclose(fptr1);
fclose(fptr2);
return 0;
int main(){
FILE *fptr1,*fptr2;
char c;
char file_path[100];
printf("--> Enter the filename OR file path to open for reading \n");
scanf("%s", file_path);
fptr1=fopen(file_path,"r");
if(fptr1==NULL){
printf("\n->> File not Found.");
}
printf("-->>Enter file Name to create a file: \n");
scanf("%s", file_path);
fptr2=fopen(file_path,"w");
if(fptr2==NULL){
printf("\n->> File Can't Open!.");
}
c=fgetc(fptr1);
while(c != EOF){
fputc(c,fptr2);
c=fgetc(fptr1);
}
printf("\n -->>> !! File Successfully Copied. !!\n");
fclose(fptr1);
fclose(fptr2);
return 0;
Expected O/P:
--> Enter the filename OR file path to open for reading
abc.txt //Enter the name of any file with extension present in the same directory.
//Or enter the Complete file path i.e /home/usr/Desktop/abc.txt
-->>Enter file Name to create a file:
New_abc.txt
-->>> !! File Successfully Copied. !!
0 Comments
Post a Comment