Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] having problem with my code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 23, 2008 2:06 pm    Post subject: [C++] having problem with my code Reply with quote

i got this code
Code:

wchar_t *szEnteredPass = new wchar_t[MAX_PATH];
               wchar_t *szRealPass = new wchar_t[MAX_PATH];
               szRealPass = _T("password");
               GetDlgItemText(hWnd,IDC_PASS_EDIT,szEnteredPass,MAX_PATH);
               if (strcmp((char*)szRealPass,(char*)szEnteredPass) == 0){
                  MessageBox(0,0,0,0);
               }

so when i enter "password" into textbox it pops up the message
so far it's good
but when i enter "passwordddd" it still pops up the messagebox!?!?
how come??

_________________
Stylo
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Oct 23, 2008 2:27 pm    Post subject: Reply with quote

1. Use TCHAR routines.
2. strcmp is ANSI
3. Use lstrcmpi for non-case sensitivity if you'd like that.

Code:
LPTSTR lpRealPass = new TCHAR[260];
LPTSTR lpPass = new TCHAR[260];

lstrcpy(lpRealPass, _T("Password"));
if (GetDlgItemText(hWnd, IDC_PASS_EDIT, lpPass, 260) > 0)
    if (!lstrcmp(lpPass, lpRealPass))
          MessageBox(hWnd, _T("Correct."), 0, 0);

delete[] lpRealPass;
delete[] lpPass;


Btw, if your using dynamic memory, use it to your advantage and only allocate enough memory required for the data your storing.

_________________


Last edited by lurc on Thu Oct 23, 2008 2:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Thu Oct 23, 2008 2:30 pm    Post subject: Reply with quote

Quote:
This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminanting null-character is reached.

Due to a null terminator being reached in one of the 2 strings, it stops checking the rest. Wink
An easy way to stop this is to also check if both strings are the same length.
Code:
if(strlen(password)==strlen(enteredpassword) && strcmp(password,enteredpassword)==0){
  Password is correct
} else {
  Password is incorrect
}

_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 23, 2008 2:34 pm    Post subject: Reply with quote

thx i got it now =]
pillboi thank u too never thought about that way Smile

_________________
Stylo
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Thu Oct 23, 2008 2:45 pm    Post subject: Reply with quote

It's how I do it, but I code in C. Wink
_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Oct 23, 2008 6:06 pm    Post subject: Reply with quote

--Pillboi-- wrote:
Quote:
This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminanting null-character is reached.

Due to a null terminator being reached in one of the 2 strings, it stops checking the rest. Wink
An easy way to stop this is to also check if both strings are the same length.
Code:
if(strlen(password)==strlen(enteredpassword) && strcmp(password,enteredpassword)==0){
  Password is correct
} else {
  Password is incorrect
}


what.

Checking the length if you're going to do that is pointless
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Thu Oct 23, 2008 6:26 pm    Post subject: Reply with quote

slovach wrote:
--Pillboi-- wrote:
Quote:
This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminanting null-character is reached.

Due to a null terminator being reached in one of the 2 strings, it stops checking the rest. Wink
An easy way to stop this is to also check if both strings are the same length.
Code:
if(strlen(password)==strlen(enteredpassword) && strcmp(password,enteredpassword)==0){
  Password is correct
} else {
  Password is incorrect
}


what.

Checking the length if you're going to do that is pointless


Why don't you read?
strcmp - compares each character until a difference is found or until a terminanting null-character is reached.

This means that password and passwordddd would return true, because a terminating null-character is reached in the first string. Checking length also, will fix this problem.
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Thu Oct 23, 2008 8:39 pm    Post subject: Reply with quote

Good luck on your program that happens to crack pins for MapleStory Very Happy
_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Oct 23, 2008 9:23 pm    Post subject: Reply with quote

smartz993 wrote:
Why don't you read?
strcmp - compares each character until a difference is found or until a terminanting null-character is reached.

This means that password and passwordddd would return true, because a terminating null-character is reached in the first string. Checking length also, will fix this problem.


you wish, you're misunderstanding, it doesn't just stop.

If the first string is shorter than the second, you'll get a negative return. Otherwise, if it's longer, you'll get a positive. If it returns zero, they match.
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Thu Oct 23, 2008 9:53 pm    Post subject: Reply with quote

Slovach is correct. Others were correct to a degree: it reaches a null early, but in BOTH strings, because characters within the ASCII set translate to UNICODE as the same byte followed by a 0 byte. So the ASCII strcmp routine only tests the first character.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 23, 2008 11:58 pm    Post subject: Reply with quote

manc wrote:
Good luck on your program that happens to crack pins for MapleStory Very Happy

oh no i'm way over maple Surprised
i'm trying to send an email via C++ window
and i got problem now with getting my computer's host
Code:

char *HostName = new char[MAX_PATH];
gethostname(HostName,MAX_PATH);

after i got the host name into HostName
i tried to put it on a static control and all i could see is something like- .........
i change character set to use multi byte in properties i don't know if it could help me
and when i want to get my host by the name the host struct remains empty
Code:

hostent *host;
host = gethostbyname(HostName); // host remain empty

_________________
Stylo
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Oct 24, 2008 1:18 pm    Post subject: Reply with quote

Did you check the last error using WSAGetLastError?
_________________
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Oct 24, 2008 2:06 pm    Post subject: Reply with quote

error: 10093 Confused
say something to you Surprised ?
edit:
Successful WSAStartup not yet performed.
Either the application has not called WSAStartup or WSAStartup failed. The application may be accessing a socket that the current active task does not own (that is, trying to share a socket between tasks), or WSACleanup has been called too many times.
took from msdn
i guess i should have initialized wsadata before taking host name XD

_________________
Stylo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites