views:

433

answers:

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

+3  A: 

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;
Naveen
Is there is any possiblity with only work with strcat without using (TCHAR,_tcscat),if possible ,please respond that in..
Rajakumar
Yes..you can do it as suggested by sharptooth.
Naveen
+2  A: 

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

sharptooth
i know but i cannot explore via coding ..if u can tell me solution through coding ..thanks
Rajakumar
i need LPCTSTR and CHAR combination only...
Rajakumar
You have only two options - if one of the strings is constant (hardcoded) you can just declare it appropriately, otherwise you need to use MultiByteToWideChar() for conversion. The latter is described in http://stackoverflow.com/questions/606075/how-to-convert-char-to-bstr/606122#606122 except that you can use malloc/free (or better new/delete) instead of SysAllocString/SysFreeString.
sharptooth
ok .fine sharptooth
Rajakumar
A: 

Pure C90:

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