Solved

Unsign char pointer comparison

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 60
Excel/Word Add-in in what language? 5 107
Embarcadero C++ Builder XE2 TDateTime 8 61
Dynamically allocate memory 9 56
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 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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

914 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

21 Experts available now in Live!

Get 1:1 Help Now