C program to copy the content of one file to another file

This page has a C program to copy the content of one file to another file. This program will read the contents from an existing file (the data file must be created earlier either through notepad or ms-word or by any other way).Then, the program will write the contents of the data files to another file. Generally, File is a collection of records arranged in an order. File may have any number of records. Each records in the file may have number of fields (Columns). I mean that, the file is just like a table. Each file may contain a unique field called primary key. In addition, each and every file can be accessable with the help of File Pointer. We can keep and use a file pointer to access any record in a file. The below given C program is used to copy the content of one file to another file. Kindly check out the program to copy the content of one file to another file.

How will ask to copy the content of one file to another file

The questions to copy the content of one file to another file can be asked as, 1). C program to copy the content of one file to another file. 2). C Program to paste the content of one file to another file. 3). C Program to keep the content of one file to another file. 4). Copy the content of one file to another file. 5). C program to copy the records of one file to another file. 6). C program to copy the content of one file to another. 7). C program to put the content of one file to another file. 8). C program to place the content of one file to another file

Copy the content of one file to another

#include<stdio.h>

int main(){

FILE *file1, *file2;

char a;

clrscr();

file1 = fopen("Data1.txt", "r");

if (file1 == NULL)

puts(" This file has no content to be coppied !!



Kindly create test1.txt file using Notepad or Ms-word");

else

{

file2 = fopen("Data4.txt", "w");

while (a != EOF){

a = fgetc(file1);

fputc(a, file2);

} // Verify the Contents of test2.txt file by opening it in Notepad or Ms-word !!

}

fcloseall();

getch();

return(0);

}

Sample Outputs: At First, Create a Text file using any Text editor (for example: notepad or notepad++ or Ms-word) before to run the program. If you do not create a text file for using it in the program with 'r' mode, the program will produce the output as "This file has no content to be coppied !!



Kindly create test1.txt file using Notepad or Ms-word". After running the program, Verify the Contents of test2.txt file by opening it in Notepad or Ms-word !!