This C Program copies a file into another file.
Here is source code of the C Program to copy a file into another file. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Copy a File into Another File
void main(int argc,char **argv)
FILE *fp1, *fp2;
if ((fp1 = fopen(argv,"r")) == NULL)
printf("\nFile cannot be opened");
printf("\nFile opened for copy...\n ");
fp2 = fopen(argv, "w");
fseek(fp1, 0L, SEEK_END); // file pointer at end of file
pos = ftell(fp1);
fseek(fp1, 0L, SEEK_SET); // file pointer set at start
ch = fgetc(fp1); // copying file character by character
$ cc file1.c $ a.out /tmp/vmlinux mylinux File opened for copy... $cmp /tmp/vmlinux mylinux $ ls -l mylinux -rw-rw-r--. 1 adi adi 3791744 Jul 27 19:57 mylinux
Sanfoundry Global Education & Learning Series – 1000 C Programs.
If you wish to look at programming examples on all topics, go to C Programming Examples.