Compare TCHAR with String value in VC ++?

How to compare TCHAR with String value in VC ++? My project is not Unicode. I do like this:

TCHAR achValue[16523] = NULL;
if(achValue == _T("NDSPATH"))
            {
                return FALSE;
            }

When achValue = "NDSPATH", then this condition does not hold.

Any help is appreciated.

+3
source share
1 answer

TCHAR or any string array is just a pointer to the first character. What you are comparing is the value of the pointer, not the string. In addition, you set the array to zero, which is pointless.

Use win32 strcmp options . If you use the _tcscmp macro, it will use the correct function for multibyte / unicode at compile time.

#define MAX_STRING 16523;

TCHAR achValue[MAX_STRING];
ZeroMemory(achValue, sizeof(TCHAR) * MAX_STRING);

sprintf(achValue, MAX_PATH, _T("NDSPATH"));

if (!_tcscmp(achValue, _T("NDSPATH"))
{
    // strings are equal when result is 0
}
+4
source

Source: https://habr.com/ru/post/1796445/


All Articles