Solved

Unsign char pointer comparison

Posted on 2003-11-10
3
1,047 Views
Last Modified: 2010-10-05
Hi,
I have a dilemma. I would like to compare images if it is the same. My idea of this is if the image is the same don’t copy it, else do.

Basically, theApp.m_pBitmap is unsigned char *m_pBitmap;

I want to copy that and compare it again.
This is what I did.
sign char *img = NULL;

strcpy(img, (char *) theApp.m_pBitmap)
if (strcmp(img,(char *)theApp.m_pBitmap)!=0)
{
//do something;
}
Did compare it correctly? What did I do wrong?

Thank all
0
Comment
Question by:musicc
3 Comments
 
LVL 3

Expert Comment

by:cindy_k
ID: 9718286
I would use memcmp instead.  StrCmp is going to look for Nulls and you won't want that.

int  memcmp ( const void * buffer1, const void * buffer2, size_t num );

Hope this helps.
Cynthia
0
 
LVL 5

Accepted Solution

by:
rendaduiyan earned 35 total points
ID: 9720808
Or you can use STL equal to do so.
template<class InputIterator1, class InputIterator2>
   bool equal
(
      InputIterator1 _First1,
      InputIterator1 _Last1,
      InputIterator2 _First2
   );
if(true == equal(img1, img1+size, img2))
....
0
 

Author Comment

by:musicc
ID: 9754695
thank you for helping me.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

760 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

23 Experts available now in Live!

Get 1:1 Help Now