Advertisement

Comparing strings

Started by April 27, 2001 08:23 AM
3 comments, last by draqza 23 years, 9 months ago
I''m working on an IRC bot and I want to check the first character of the message to see if it''s a carret. Right now, I have this line: if (msg->m_lpszPlainText[0]=="^") //error It responds with an indirection error (I think) and says it can''t convert a char * to int. How can I fix this? -- WNDCLASSEX Reality; ... ... Reality.lpfnWndProc=ComputerGames; ... ... RegisterClassEx(&Reality); Unable to register Reality...what''s wrong? --------- Dan Upton Lead Designer WolfHeart Software
WNDCLASSEX Reality;......Reality.lpfnWndProc=ComputerGames;......RegisterClassEx(&Reality);Unable to register Reality...what's wrong?---------Dan Uptonhttp://0to1.orghttp://www20.brinkster.com/draqza
I''ve had this problem before, you see you said this:


if (msg->m_lpszPlainText[0]=="^")

you should write

draqza I''m working on an IRC bot and I want to check the first character of the message to see if it''s a carret. Right now, I have this line:

if (msg->m_lpszPlainText[0]==''^'')

notice the use of '' '' instead of " " quotes ? Use single quotations and you should be alright. I can''t explain exactly what the error means and why u should use single quotes but it should work, especially when you are comparing a single character.
Hope I helped


Dark Star



---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Advertisement
Hi!
That''s quite an easy issue.
Just change the "^" into a ''^''.
That will make the difference. Another way would be to look into the ASCII-Table and take the int-value for the specific character.
But let me give you one tip: Use the std::string class as often as possible when you need string manipulation and comparisson.
That will make life much more easy and powerful for you.
Hope I could help you with that.

Cu,
Florian
Visit:http://www.evildawncrew.comAll things which are worth beeing done, are worth beeing donw well.
I feel kind of stupid about that...I thought about trying single quotes but must have gotten sidetracked. Anyway, thanx for your help!

quote:

But let me give you one tip: Use the std::string class as often as possible when you need string manipulation and comparisson.



do you mean strcmp()? I thought about trying that, too, but decided to put off the rest of my coding until I'd be able to connect and test it.

Edited by - draqza on April 27, 2001 9:36:27 AM
WNDCLASSEX Reality;......Reality.lpfnWndProc=ComputerGames;......RegisterClassEx(&Reality);Unable to register Reality...what's wrong?---------Dan Uptonhttp://0to1.orghttp://www20.brinkster.com/draqza
> if (msg->m_lpszPlainText[0]=="^") //error

Simple!

Just change the "^" to ''^''
"^" is a char pointer, ''^'' is a value

/ remar

This topic is closed to new replies.

Advertisement