RGS
RGS

Reputation: 4253

copy file to windir c

I need to copy one file to windir, So I do:

TCHAR windir[MAX_PATH];
GetWindowsDirectory(windir, MAX_PATH);

to get the windir.

char newLocation[]="text.txt"; // how to add the windir here?
BOOL stats=0;
CopyFile(filename, newLocation, stats);

My problem is, I want to add the windir value before the text.txt in char newLocation[].

Any ideas?

Upvotes: 1

Views: 244

Answers (1)

gsamaras
gsamaras

Reputation: 73424

Did you try concatenating the strings, like this?

#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;
}

If that won't work, give wcscat() a shot!


Sources:

  1. How do I concatenate two strings in C?
  2. What is difference between TCHAR and WCHAR?
  3. C++ Combine 2 Tchar

Upvotes: 1

Related Questions