Solved

Data Type question

Posted on 1998-08-31
1
160 Views
Last Modified: 2010-04-10
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
Comment
Question by:ds1964
1 Comment
 
LVL 2

Accepted Solution

by:
milenvk earned 30 total points
ID: 1171763
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question