By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

comparing char*

P: n/a
I want to compare the commandline string with "run" and only run the
app if they are equal. This however does not work even though I can
see pCommandString showing as "run" in the debugger!

LPSTR is #defined as a char*

What am I missing?

thanks

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInst, LPSTR
pCommandString, INT)
{
if (pCommandString == "run")
{
//do stuff
}

return 0;
}
Jun 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
scroopy wrote:
I want to compare the commandline string with "run" and only run the
app if they are equal. This however does not work even though I can
see pCommandString showing as "run" in the debugger!

LPSTR is #defined as a char*

What am I missing?
It seem that you think that comparing two pointers is in some magical way
transformed into a string comparison. That's not the case. Try the strcmp()
function instead.
thanks

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInst, LPSTR
pCommandString, INT)
{
if (pCommandString == "run")
{
//do stuff
}

return 0;
}


Jun 16 '06 #2

P: n/a
On Fri, 16 Jun 2006 13:47:56 +0200, Rolf Magnus <ra******@t-online.de>
wrote:
scroopy wrote:
I want to compare the commandline string with "run" and only run the
app if they are equal. This however does not work even though I can
see pCommandString showing as "run" in the debugger!

LPSTR is #defined as a char*

What am I missing?
It seem that you think that comparing two pointers is in some magical way
transformed into a string comparison. That's not the case. Try the strcmp()
function instead.


I get the same problem Rolf. For some reason the compare fails...
thanks

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInst, LPSTR
pCommandString, INT)
{
if (pCommandString == "run")
{
//do stuff
}

return 0;
}

Jun 16 '06 #3

P: n/a
Ignore my last post. I thought strcmp returned 1 if they were equal...
foh

On Fri, 16 Jun 2006 13:42:06 +0100, scroopy <sc*****@doesntexist.com>
wrote:
On Fri, 16 Jun 2006 13:47:56 +0200, Rolf Magnus <ra******@t-online.de>
wrote:
scroopy wrote:
I want to compare the commandline string with "run" and only run the
app if they are equal. This however does not work even though I can
see pCommandString showing as "run" in the debugger!

LPSTR is #defined as a char*

What am I missing?


It seem that you think that comparing two pointers is in some magical way
transformed into a string comparison. That's not the case. Try the strcmp()
function instead.


I get the same problem Rolf. For some reason the compare fails...
thanks

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInst, LPSTR
pCommandString, INT)
{
if (pCommandString == "run")
{
//do stuff
}

return 0;
}

Jun 16 '06 #4

P: n/a
scroopy posted:
I want to compare the commandline string with "run" and only run the
app if they are equal. This however does not work even though I can
see pCommandString showing as "run" in the debugger!

LPSTR is #defined as a char*

What am I missing?

thanks

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInst, LPSTR
pCommandString, INT)
{
if (pCommandString == "run")
{
//do stuff
}

return 0;
}

Use "strcmp". Or if you want to be a cowboy about it:

if ( *pCommandString == 'r'
&&
pCommandString[1] == 'u'
&&
pCommandString[2] == 'n'
&&
!pCommandString[3] )
{
DoStuff();
}

--

Frederick Gotham
Jun 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.