Rajakumar
Rajakumar

Reputation: 442

string concatenate char* with LPCTSTR

LPCTSTR Machine=L"Network\\Value";
char s[100]="Computer\\";
strcat(s,(const char*)Machine); 
printf("%s",s); 

Here i received output Computer\N only i expect output like Computer\Network\Value . Give Solution for that..

Upvotes: 1

Views: 4239

Answers (3)

AProgrammer
AProgrammer

Reputation: 52334

Pure C90:

wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));

Upvotes: 0

sharptooth
sharptooth

Reputation: 170559

You try to cancat an ANSI string with a Unicode string. That won't work. Either make the fisrt string ANSI

LPCSTR Machine="Network\\Value";

or convert the second one with MultiByteToWideChar().

Upvotes: 2

Naveen
Naveen

Reputation: 73503

The string pointed Machine is a unicode string and hence has one NULL character after the character 'N'. So if you use non-unicode string concatanation you will get the output like that. You should not mix the unicode and non-unicode strings like that. You can do it like this:

LPCTSTR Machine=L"Network\\Value";
TCHAR  s[100]=_T("Computer\\");
_tcscat(s,Machine); 
std::wcout<<s;

Upvotes: 3

Related Questions