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

Naveen
  • 74,600
  • 47
  • 176
  • 233
Rajakumar
  • 442
  • 1
  • 9
  • 21

3 Answers3

3

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
  • 74,600
  • 47
  • 176
  • 233
2

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
  • 167,383
  • 100
  • 513
  • 979
  • i know but i cannot explore via coding ..if u can tell me solution through coding ..thanks – Rajakumar Aug 12 '09 at 05:21
  • 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 Aug 12 '09 at 05:39
0

Pure C90:

wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));
AProgrammer
  • 51,233
  • 8
  • 91
  • 143