Hello,

i am trying to write a C program to copy a file from one directory and copy that to another directory. I am new to file handling and dont know how to proceed further. could you please guide me how to implement the property in the c code to copy a file.


Thanks

Open the original file for reading. Open the new file for writing. Then in a loop read a block of data from the input file and write it back out to the output file. Since we don't know whether the original file was write in text or binary mode its always safest to assume binary mode. And I like to read blocks of data in chuncks of 255 bytes, but you can make it almost anything you want.

open input file in binary mode
open output file in binary mode
loop
   read a block of data from input file
   write the block to output file
end of loop
close both files
Comments
His views helps me a lot

hi Man,
Thank you for your reply.
Could you please give me some sample codes or links containing that.
Also the requirement of my project is that i have to check the contents of the file first and copy the contents of a file which is present in some other directory.

You give it a try yourself, then post back with the code you have written if you have more questions. Yes you may have to do some studying about FILE* and associated functions which I can not do for you. Also google around for c file handline tutorials to help you out with your research. Nothing teaches you better than when you research and discover the solutions to these things yourself.

is it possible to copy a zip file and exe file from one directory to another using c program?

is it possible to copy a zip file and exe file from one directory to another using c program?

Yes.

do we have any specific commands to perform that?
could you please guide me with a sample code...

Thanks

I guess you want us to write the program for you. Ain't going to happen in this lifetime. Show us that you have made an effort and posted the code you have written.

i didnt ask for a program... i asked whether there is any specific method to copy a exe file or zip file.

i didnt ask for a program... i asked whether there is any specific method to copy a exe file or zip file.

No.

This article has been dead for over six months. Start a new discussion instead.