复制文件到 windir c
copy file to windir c
我需要复制一个文件到windir,所以我这样做:
TCHAR windir[MAX_PATH];
GetWindowsDirectory(windir, MAX_PATH);
获取windir。
char newLocation[]="text.txt"; // how to add the windir here?
BOOL stats=0;
CopyFile(filename, newLocation, stats);
我的问题是,我想在 char newLocation[] 中的 text.txt 之前添加 windir 值。
有什么想法吗?
你试过像这样连接字符串吗?
#include <stdlib.h>
#include <string.h>
char* concat(char *s1, char *s2)
{
char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator
//in real code you would check for errors in malloc here
strcpy(result, s1);
strcat(result, s2);
return result;
}
如果不行,请 wcscat() 试一试!
来源:
- How do I concatenate two strings in C?
- What is difference between TCHAR and WCHAR?
- C++ Combine 2 Tchar
我需要复制一个文件到windir,所以我这样做:
TCHAR windir[MAX_PATH];
GetWindowsDirectory(windir, MAX_PATH);
获取windir。
char newLocation[]="text.txt"; // how to add the windir here?
BOOL stats=0;
CopyFile(filename, newLocation, stats);
我的问题是,我想在 char newLocation[] 中的 text.txt 之前添加 windir 值。
有什么想法吗?
你试过像这样连接字符串吗?
#include <stdlib.h>
#include <string.h>
char* concat(char *s1, char *s2)
{
char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator
//in real code you would check for errors in malloc here
strcpy(result, s1);
strcat(result, s2);
return result;
}
如果不行,请 wcscat() 试一试!
来源:
- How do I concatenate two strings in C?
- What is difference between TCHAR and WCHAR?
- C++ Combine 2 Tchar