Solved

Unsign char pointer comparison

Posted on 2003-11-10
3
1,058 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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…
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 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.

688 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