Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
File Handling: Copy Content of One File to Another in C
WhatsApp
Mr Shanawar
Jan 25
2016
1.5
k
0
0
/*
Name: SHANAWAR
Copyright:
Description: PROGRAM THAT READS DATA FROM ONE FILE AND WRITE IT ON ANOTHER FILE.
*/
#include<stdio.h>
#include<conio.h>
int
main()
{
FILE
*fr,*fw;
// file pointers
char
fname[20],fname2[20],str[80];
printf(
"Source file name"
);
gets(fname);
// fopen( file_name , mode)
if
( ( fr = fopen(fname,
"r"
) ) == NULL )
// "r" represents read mode
{
// if fr is equals to NULL it means file can't open
printf(
"File Can't Open"
);
return
1;
}
printf(
"Enter Target file name"
);
gets(fname2);
if
( ( fw = fopen(fname2,
"a"
) ) == NULL)
// "a" represents append mode
{
// if fw is equals to NULL it means file can't open
printf(
"File Can't Open"
);
return
1;
}
while
( fgets(str,80,fr) != NULL )
// reading strings from source file
{
fputs(str,fw);
// writing strings into target file
}
// close opened files
fclose(fr);
fclose(fw);
getch();
return
0;
}
File handling
Copy Content of One File to Another.C
Up Next
File Handling: Copy Content of One File to Another in C