Copy Files in C++

Hiho for all...
I need copy HTML files... i'm using this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void copyFile(char *in,char *out){

    FILE *arqIn = fopen(in,"rb");
    FILE *arqOut = fopen(out,"w");

    char c;
    while(!feof(arqIn)){
        fscanf(arqIn,"%c",&c);
        fprintf(arqOut,"%c",c);
    }

    fclose(arqIn);
    fclose(arqOut);

}


but the file is destroyed...

Begin of Original file:
1
2
3
4
<?xml version="1.0" encoding="UTF-16LE"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Note: this file is an XHTML 1.0 document constructed to be rendered properly in most web browsers
that do not support XHTML natively. Be careful to respect the XHTML 1.0 syntax if you manually edit this file -->

Begin of Copied file:
1
2
3
4
<?xml version="1.0" encoding="UTF-16LE"?>
਍㰀℀䐀伀䌀吀夀倀䔀 栀琀洀氀 倀唀䈀䰀䤀䌀 ∀ⴀ⼀⼀圀㌀䌀⼀⼀䐀吀䐀 堀䠀吀䴀䰀 ㄀⸀  吀爀愀渀猀椀琀椀漀渀愀氀⼀⼀䔀一∀ ∀栀琀琀瀀㨀⼀⼀眀眀眀⸀眀㌀⸀漀爀最⼀吀刀⼀砀栀琀洀氀㄀⼀䐀吀䐀⼀砀栀琀洀氀㄀ⴀ琀爀愀渀猀椀琀椀漀渀愀氀⸀搀琀搀∀㸀ഀഀ
<!-- Note: this file is an XHTML 1.0 document constructed to be rendered properly in most web browsers
਍琀栀愀琀 搀漀 渀漀琀 猀


anybody here can helpme?
Hi, This looks like some mixup with Unicode,MCBS conversion.
If you just want to copy the file, I'd recommend using the shell copy function since you're under windows, using FO_COPY in the SHFILEOPSTRUCT structure. It will call for user rights automatically on files that are restricted too, since it uses the shell.
http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx
Sorry, I look for what you told me but I don't know how use it. You can give me any example using C++? Thanks
A snippit from how I used it in some code, just fill in the src and dst arrays with your filenames.
Don't forget to include #include <shellapi.h> and the associated library file if needed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	char src[MAX_PATH];		// Source filename for the copy.
	char dst[MAX_PATH];		// Destination filename for the copy.
	SHFILEOPSTRUCT fos;		// The structure WIN32 uses to specify what is to be copied and how.
	memset(&fos, 0, sizeof(fos));
	// Fill in src and dst with the source and destination filenames somewhere here.
	....
	// Setup the structure for file copy.
	fos.pFrom = src;
	fos.pTo = dst;
	fos.hwnd = hWnd;		// This can be set to NULL if you don't have a window handle.
	fos.wFunc = FO_COPY;
	fos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMMKDIR;
	// Use the windows shell file copy as this asks the user for copy permissions, rather than just failing.
	if(SHFileOperation(&fos))	// Does the file copy here.
	{
		// Something went wrong so tell the user.
		......
Last edited on
Topic archived. No new replies allowed.