Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

Data Type question

I have a snippet of code:
for (i=0; i<TagCount; i++)
{
iErr = ADL_Tag_Get(TDL, i + 1, &TagInfo);
if (TagInfo.name == "ZIP4")    //error here
break;
}

It gives me this error:
'==' : no conversion from 'char *' to 'unsigned char *'
                        
0
ds1964
Asked:
ds1964
1 Solution
 
milenvkCommented:
I assume you are programming for any of the Windows operating systems.

This code here will do the job:

if(wcscmp(TagInfo.name, L"ZIP4") == 0) // error here
  break;

See, fisrt I don't think that '==' is the operator that will help you for string comparison. '==' compares the two pointers not the two strings. Further if you look at the declaration of the structure/class of TagInfo you will probably see that 'name' is of type LPWSTR or LPOLECHAR or any other alias to 'unsigned char*'. This is the wide character format and therefore you need to convert your literal constant "ZIP4" to wide character format. That's why there is an 'L' infront of "ZIP4" in my example. 'L' makes the constant wide format. And finally the function wcscmp is the wide character version of strcmp, which compares two strings and returns 0 if they are equal.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now