Solved

Data Type question

Posted on 1998-08-31
1
156 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now