Solved

Data Type question

Posted on 1998-08-31
1
162 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

830 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