SteveWood
asked on
Easy --- File Copy -- but urgent
Can anyone show me some code that will copy a file from one directory into another?
/* Error handling omitted */
#include <stdio.h>
FILE *file1, *file2;
int c;
file1 = fopen(<source filename>, "r");
file2 = fopen(<dest filename>, "w");
while ((c = getc(file1)) != EOF)
putc(c, file2);
fclose(file1);
fclose(file2);
#include <stdio.h>
FILE *file1, *file2;
int c;
file1 = fopen(<source filename>, "r");
file2 = fopen(<dest filename>, "w");
while ((c = getc(file1)) != EOF)
putc(c, file2);
fclose(file1);
fclose(file2);
Err, those filenames actually meant pathnames.
ASKER
mlev -- I Think this will only work for text files. I need something that will copy any type of file.
Will be in a console app that needs to run on NT and 95/98.
I am using VC++ 5
Will be in a console app that needs to run on NT and 95/98.
I am using VC++ 5
ASKER
If anyone can provide me with an example CopyFile program that might be usefull to me, I could see if that does the trick.
mlev - If your previous answer proves correct I will give you the points. I can't test it as it won't compile on my machine.
mlev - If your previous answer proves correct I will give you the points. I can't test it as it won't compile on my machine.
There you are!
What is the status on the strstr problem?
What is the status on the strstr problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mlev's example is as straightforward and simple as you can get, and should work or be very close. You mkight need to make the "r" and "w" into "rb" and "wb" to handle binary files, not certain which way it defaults. And of course you need to replace <source filename> with a path and filename string. Why doesn't it compile?
ASKER
Cheers chrisbill this works a treat.
in windows theer is an API call CopyFile which will do it for u
In dos in TC u can use SYSTEM comand to do that,
please give more explanation to u'r question please..