Compare TCHAR with String value in VC++?
How to Compare TCHAR with String value in VC++ ? My project is not Unicode. I am doing like this :
TCHAR achValue[16523] = NULL;
if(achValue == _T("NDSPATH"))
{
return FALSE;
开发者_运维知识库 }
When achValue = "NDSPATH" then also this condition does not staisfy.
Any help is appreciated.
A TCHAR or any string array is simply a pointer to the first character. What you're comparing is the value of the pointer, not the string. Also, you're assigning an array to null which is nonsensical.
Use win32 variations of strcmp. 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
}
精彩评论