Q. Write a program to copy content of one file into another file.
#BIT-C Programming-2019-GroupB-9No-4 Marks-Solution
#AssignmentNo12
==> Code goes like this:
#include <stdio.h>
main()
{
FILE *fptrSource, *fptrDest;
char ch;
fptrSource = fopen("D:\\original.txt", "r");
if(fptrSource==NULL)
{
printf("\n FIle can not be opened");
exit(1);
}
fptrDest = fopen("D:\\newfile.txt", "w");
if(fptrDest==NULL)
{
printf("\n File can not be created");
exit(1);
}
while((ch = getc(fptrSource)) != EOF)
putc(ch, fptrDest);
printf("\n Successfully copied!!!");
fclose(fptrSource);
fclose(fptrDest);
return 0;
}
Output:
Note : You have to create original.txt in D: first with some content inside it.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Copying content of one file to another file - C
12:29 PM
AssignmentSolutionC
,
C Programs
,
copying content of one file to another file in C
,
file handling
,
OldQuestionSoluton2019C
Edit
0 comments:
Post a Comment