-
July 31st, 2008, 09:18 AM
#1
Why doesnt this memcmp work???
Im new to c++ so bare with me.. This code compiles but it doesnt stop when they are equal.. Whats my problem?
Code:
static TCHAR * szUp = TEXT ("Up")
TCHAR szKeyName[32];
if (memcmp(szKeyName, szUp, 2)) {
s_selected[mapSudokuBoard[hwnd]] = 0 ;
SetFocus (s_window[mapSudokuBoard[hwnd] - 9]);
}
Last edited by tgreaves; July 31st, 2008 at 09:36 AM.
-
July 31st, 2008, 09:26 AM
#2
Re: Why doesnt this memcmp work???
Have you checekd the return values for memcmp? 0 indicates equality.
Wouldn't strcmp be better here?
-
July 31st, 2008, 09:28 AM
#3
Re: Why doesnt this memcmp work???
I havent checked the values as of yet.. My boss is a c++ programmer and thats just what he told me to use.. Ill check out strcmp also..
-
July 31st, 2008, 09:31 AM
#4
Re: Why doesnt this memcmp work???
Originally Posted by GCDEF
Wouldn't strcmp be better here?
Sure, you meant _tcscmp
Victor Nijegorodov
-
July 31st, 2008, 09:35 AM
#5
Re: Why doesnt this memcmp work???
Very strange.. This code below works..
Code:
iMyInt = memcmp(szKeyName, szUp, 2);
if (iMyInt == 0) {
s_selected[mapSudokuBoard[hwnd]] = 0 ;
SetFocus (s_window[mapSudokuBoard[hwnd] - 9]);
}
Any ideas whats wrong with my first bit of code at the top?
-
July 31st, 2008, 09:42 AM
#6
Re: Why doesnt this memcmp work???
Originally Posted by tgreaves
Very strange.. This code below works..
Code:
iMyInt = memcmp(szKeyName, szUp, 2);
if (iMyInt == 0) {
s_selected[mapSudokuBoard[hwnd]] = 0 ;
SetFocus (s_window[mapSudokuBoard[hwnd] - 9]);
}
Any ideas whats wrong with my first bit of code at the top?
Sure. In the first you're testing for non-zero, in the second you're testing for zero.
Change the first one to
Code:
if (memcmp(szKeyName, szUp, 2) == 0)
{
s_selected[mapSudokuBoard[hwnd]] = 0 ;
SetFocus (s_window[mapSudokuBoard[hwnd] - 9]);
}
and it will work too.
Last edited by GCDEF; July 31st, 2008 at 09:45 AM.
-
July 31st, 2008, 09:44 AM
#7
Re: Why doesnt this memcmp work???
Originally Posted by VictorN
Sure, you meant _tcscmp
In all the years I've been doing this, Unicode has never been an issue I've ever had to think about. Maybe it's just me. FWIW, selecting _tcscmp documentation in MSDN brings up strcmp documentation.
-
July 31st, 2008, 09:56 AM
#8
Re: Why doesnt this memcmp work???
Originally Posted by GCDEF
Sure. In the first you're testing for non-zero, in the second you're testing for zero.
Change the first one to
Code:
if (memcmp(szKeyName, szUp, 2) == 0)
{
s_selected[mapSudokuBoard[hwnd]] = 0 ;
SetFocus (s_window[mapSudokuBoard[hwnd] - 9]);
}
and it will work too.
I thought "if (!memcmp(szKeyName,szUp,2))" was testing for not zero???
-
July 31st, 2008, 09:59 AM
#9
Re: Why doesnt this memcmp work???
Sigh. It is. That's why I add == 0 to the if statement.
A return of 0 indicates equality. You're testing to see if the different.
-
July 31st, 2008, 10:08 AM
#10
Re: Why doesnt this memcmp work???
Originally Posted by GCDEF
In all the years I've been doing this, Unicode has never been an issue I've ever had to think about.
Consider yourself fortunate.
-
July 31st, 2008, 10:55 AM
#11
Re: Why doesnt this memcmp work???
Originally Posted by tgreaves
I havent checked the values as of yet.. My boss is a c++ programmer and thats just what he told me to use.. Ill check out strcmp also..
Then why not using std::string?
Code:
std::string stringOne ="Blah";
std::string stringTwo ="Nada";
if (stringOne == stringTwo)
{
// string are the same
}
else
{
// strings are not the same
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|