Question

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..

Was it helpful?

Solution

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().

OTHER TIPS

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;

Pure C90:

wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top