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 / C++ problem LPSTR to char[]

Author
Message
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 31st Jan 2009 16:48
I have a LPSTR pointer to a filename "colormap.png" and I want to store this into a char[] so I can do something like this...

I know that LPSTR is equal to char*
What I dont know is how to get that information into char[]


if(myfilename == "colormap.png")
{
//do something here
}

thank you.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 31st Jan 2009 16:52
Use strcmp() to compare c-style strings, where a return value of 0 means they match, otherwise you're just comparing the addresses of the char*.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jan 2009 16:55
Quote: "if(myfilename == "colormap.png")"

That only works in VC++ in release mode if you have string pooling enabled, and assigned your variable from another constant string with exactly the same length and case. Even then, that's not a guarantee.

david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 31st Jan 2009 19:05 Edited at: 31st Jan 2009 19:05
ok then so if that wont work then how am I suppose to test if its true?

could I do something like this.

//myfilename is a pointer to LPSTR..that points to a filename
//so myfilename is equal to char*

myfilename

char *MyString= "color.png";


if(strcmp (myfilename,MyString) == 0)
{
//do something
}
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 31st Jan 2009 19:08
Ok I got it working thanks DC and IanM.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Feb 2009 00:09 Edited at: 1st Feb 2009 00:10
Or Look at how JFC_STRING does it Bro!
--Jason

[edit]and JFC_STRINGW[/edit]

Login to post a reply

Server time is: 2024-09-30 17:26:19
Your offset time is: 2024-09-30 17:26:19