Solved

Unsign char pointer comparison

Posted on 2003-11-10
3
1,052 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

791 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