Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How do I copy files?
How do I copy files?
✍: Guest
Either use system() to invoke your operating system's copy utility, or open the source and destination files (using fopen or some lower-level file-opening system call), read characters or blocks of characters from the source file, and write them to the destination file. Here is a simple example:
#include <stdio.h>
int copyfile(char *fromfile, char *tofile)
{
FILE *ifp, *ofp;
int c;
if((ifp = fopen(fromfile, "r")) == NULL) return -1;
if((ofp = fopen(tofile, "w")) == NULL) { fclose(ifp); return -1; }
while((c = getc(ifp)) != EOF)
putc(c, ofp);
fclose(ifp);
fclose(ofp);
return 0;
}
To copy a block at a time, rewrite the inner loop as
while((r = fread(buf, 1, sizeof(buf), ifp))> 0)
fwrite(buf, 1, r, ofp);
where r is an int and buf is a suitably-sized array of char.
2015-04-08, 1177👍, 0💬
Popular Posts:
What Information Is Needed to Connect SQL*Plus an Oracle Server? - Oracle DBA FAQ - Introduction to ...
How To Fade Image Edges to Background Colors? - PSP Tutorials - Fading Images to Background Colors w...
How do we host a WCF service in IIS? Note: - The best to know how to host a WCF in IIS is by doing a...
How To Blend a Color Layer to a Image? - PSP Tutorials - Fading Images to Background Colors with PSP...
Which one of the following statements is TRUE in regard to overloading the ++ operator? 1 You cannot...