C Program to copy one file into another file

list of progrtams below: C Program to copy one file into another file using functions, C Program to copy one file into another file without functions

C Program to copy one file into another file using functions without functions
C Program to copy one file into another file

To write a c program to copy one file into another file i.e. to write a c program to copy contents of one file into another file, we need a source file and a destination file . Open the source file, copy the contents of source from (pointer) starting to end of file an open destination file and add contents of source upto end of file

Write a C Program to copy contents of one file into another file using functions

Write a C Program to copy one file into other file 

#include<stdio.h>
void main()
{
char sf, df [20];
printf(“C Program to copy contents of one file into another file…\n:”);
printf(“\n Enter the source file:”);
gets(sf);
printf(“\n Enter the destination file:”);
gets(df);
Copy_file_Contents(sf,df);
getch();
}

void Copy_file_Contents(char source_File_name[20], char des_File_name[20] )
{
FILE *f1,*f2;
char ch;
f1=fopen(source_File_name,”r”);
if(f1==NULL)
{
printf(“cannot open: %s”, source_File_name);
exit(0);
}
f2=fopen(des_File_name,”w”);
if(f2==NULL)
{
printf(“cannot open %s”, des_File_name);
exit(0);
}
while((ch=getc(f1))!=EOF)
putc(ch,f2);
printf(“\nCOMPLETED”);
fclose(f1);
fclose(f2);
}

OUTPUT:

To copy contents of one file into another file…
Enter the source file: Hello.txt
Enter the destination file: Bye.txt
COMPLETED

Write a C Program to copy one file into another file without functions

Write a C Program to copy one file into another file without functions

#include<stdio.h>
void main()
{
FILE *f1,*f2;
char source_File_name[20], des_File_name [20];
char ch;
printf(“C Program to copy contents of one file into another file…\n:”);
printf(“\n Enter the source file:”);
gets(source_File_name);
f1=fopen(source_File_name,”r”);
if(f1==NULL)
{
printf(“cannot open: %s”, source_File_name);
exit(0);
}
printf(“\n Enter the destination file:”);
gets(des_File_name);
f2=fopen(des_File_name,”w”);
if(f2==NULL)
{
printf(“cannot open %s”, des_File_name);
exit(0);
}
while((ch=getc(f1))!=EOF)
putc(ch,f2);
printf(“\n COMPLETED”);
fclose(f1);
fclose(f2);
getch();
}

OUTPUT:

C Program to copy contents of one file into another file..
Enter the source file: one.txt
Enter the destination file: two.txt
COMPLETED

 

Leave a Reply

Your email address will not be published. Required fields are marked *