How to write a C Program to copy a file to another file in C Programming Language ?
This C Program to copy a file to another file.
Solution:
- #include<stdio.h>
- void main()
- {
- FILE *fp1,*fp2;
- char ch;
- char fname1[30],fname2[30];
- printf("Enter the source file: ");
- fflush(stdin);
- scanf("%s",fname1);
- printf("Enter the destination file: ");
- fflush(stdin);
- scanf("%s",fname2);
- fp1=fopen(fname1,"r");
- fp2=fopen(fname2,"w");
- if(fp1==NULL)
- {
- printf("\n cannot open file %s for reading",fname1);
- exit(1);
- }
- else if(fp2==NULL)
- {
- printf("\n cannot open file %s for writing",fname2);
- exit(1);
- }
- else
- {
- ch=getc(fp1);
- while(ch!=EOF)
- {
- putc(ch,fp2);
- ch=getc(fp1);
- }
- fclose(fp1);
- fclose(fp2);
- printf("\n files copied");
- }
- }
Learn More :
File Handling
File
- COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM
- C Program File Input & Output Example
- C Program To Destruc Self Execution File ?
- C Program To Store Students Record In A Text File
- C Program To Write Data In A File And Search Data From File
- Make a copy of file given in argv[1] to file given in argv[2]
- C Function to read instructions from the file and obey them
- Client/Server C program to make client send the name of a file
- A small I/O bound program to copy N bytes from an input file to an output file.
- C Program to Read and Write FIFO
- File Number Control C Program Example
- C Program to opens and reads dictionary file specified in spellrc
- C Program to Recursively converts all file-names to lower-case
- C Program to Find the Size of File using File Handling Function
- C Program Recursive function that searches for a given file in a given folder
- C Program Read a char & print next char ( file to file )
- C Program to Input Student Details into a File For Two Subjects
- Identifies the architecture Windows PE (exe or dll) file was compiled C Program
- File Handling (console to file) in C Program
Copy
- COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM
- C Program To Copy One Character Array Into Another
- C Program/Code to Copies a BMP piece by piece
- Make a copy of file given in argv[1] to file given in argv[2]
- A small I/O bound program to copy N bytes from an input file to an output file.
- C Program to Create a copy of an image
- C Program Copies a BMP piece by piece
- Menu driven program in C to Calculate Length, Copy into Another Compare Concatenate of Two String