Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / find character

Author
Message
Dimension
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 18th Aug 2010 01:45
I'm creating a function to find the position of a character and for some reason it can't see when the characters are equal.



But when I modify the code as follows for some reason it works



Does anybody know why this is?
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 18th Aug 2010 01:59
In the first code snippet, you are comparing two pointers, which are addresses in memory. You are not comparing the strings themselves, just where they are located in memory.

In the second snippet, you are comparing the strings correctly, byte by byte, but there is an easier way.

Use strcmp.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Dimension
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 18th Aug 2010 02:39
Thanks for the help.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Aug 2010 06:29
Keep in mind dbMid returns a string on the heap, so your code will leak memory. Such a function doesn't even require GDK functions, just do something like:



Of course a better method would be to use a string class, such as std::string which has find_first_of.

Login to post a reply

Server time is: 2024-11-19 18:28:10
Your offset time is: 2024-11-19 18:28:10