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 / Annoying string problem

Author
Message
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 26th Jun 2009 22:00 Edited at: 26th Jun 2009 22:02
Hi! I'm working on a command prompt type of thing to make selections rather then making a toolbar. So I have 3 possible options: Load, Save(export), Import. I have a API prompt that pops up and asks for a command. Then I type in "Load" exactly how it is in my if structure. When the API prompt closes I use

then I go through the decision structure but it doesn't load anything. So I test to see if it will load the map not matter when I type in and it does. Then I check what exactly is returned from the API prompt and sure enough... it's "Load". So, my text variable has the value "Load" in it and my if structure is:

So why doesn't this work? Thanks!

Jumpster
16
Years of Service
User Offline
Joined: 7th Feb 2008
Location:
Posted: 26th Jun 2009 22:04
You can't just use == to compare strings. Use strcmp() instead.

Regards,
Jumpster
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 26th Jun 2009 22:09 Edited at: 26th Jun 2009 22:17
Hmm, still doesn't work. But, that strcmp() is good to know for future reference

P.S. I declared text as

if it matters

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 26th Jun 2009 22:21
Quote: "Hmm, still doesn't work."

Yes it does.

heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 26th Jun 2009 22:25 Edited at: 26th Jun 2009 22:27
Hmmm not it doesn't, why would I lie? I'm thinking it's something to do with the API code that I used... Here it is if you can figure it out (WARNING: they're long):

Win32InputBox.h:


Win32InputBox.cpp:


Code to use the input box:


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 26th Jun 2009 22:27
What doesn't work? I don't see a 'strcmp' in there anywhere.

heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 26th Jun 2009 22:28 Edited at: 26th Jun 2009 22:30
This doesn't work:

I think it has something to do with the way Command is declared but that's the only way to declare it and use it with the input box.

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 26th Jun 2009 22:29
Keep in mind that strcmp() returns either -1, 0 or 1. You have to check that strcmp() == 0 in order for the strings to match.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 26th Jun 2009 22:31
I don't see that in the code boxes you posted before?

Either way, you're not using strcmp correctly.

heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 26th Jun 2009 22:32 Edited at: 26th Jun 2009 22:33
Oh lol, sorry didn't know about the -1, 0, 1 thing. Now it works .

@Benjamin - That's because i never updated the code box with the decision structure

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 27th Jun 2009 01:28
Keep in mind that strcmp is also case sensitive, just in case you're expecting user input. Use stricmp() if you want a case insensitive comparison.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 27th Jun 2009 01:49
Ok thanks lilith!

MirrorLink
15
Years of Service
User Offline
Joined: 25th Jun 2009
Location:
Posted: 28th Jun 2009 02:32
lol

these windows typedef's give me the creeps

well if i were you i would use a std::string instead..

it's == operator is already overloaded ^^'

Login to post a reply

Server time is: 2024-10-01 05:51:47
Your offset time is: 2024-10-01 05:51:47