Page 1 of 1

if text="text"?

PostPosted: Tue May 24, 2011 2:52 pm
by Hblade
Hi everybody :) I've tried many ways of having something happen IF the text is equal to this, or that... however I can't seem to get it to work :P Example codes I tried:
Code: Select all
//Try # 1:
if (strcmp(PWD.text, "c7756453f8")) {
    view.x+=640;
} //This test ended in it making the view go regardless of the password Oo

//Try # 2:
if (PWD.text == "c7756453f8") {
    view.x+=640;
}


Can anybody help with this? XD Im so confused as to why its not working

Re: if text="text"?

PostPosted: Tue May 24, 2011 3:00 pm
by lcl
Code for checking if equal is this:
Code: Select all
if (strcmp(myLine, "hello") == 0)
{
    //blah…
}

0 is for that strcmp() compares the strings values (every char has own value) and returns the dfference between the lines' values. (I think.) :lol:

Re: if text="text"?

PostPosted: Tue May 24, 2011 3:10 pm
by Hblade
Thank you so much! :)

Re: if text="text"?

PostPosted: Tue May 24, 2011 4:04 pm
by lcl
Hblade wrote:Thank you so much! :)

You're welcome! :)

Re: if text="text"?

PostPosted: Tue May 24, 2011 8:42 pm
by Game A Gogo
The documentation is where to look at for things like this... it explains 99% of all functions!

Re: if text="text"?

PostPosted: Tue May 24, 2011 11:22 pm
by Hblade
True but I'd get my answeres from here faster, because my attention span.

Re: if text="text"?

PostPosted: Mon Jun 13, 2011 1:04 pm
by Jagmaster
Will this check if string is empty?
Code: Select all
if(strcpy(string, 0,)==1)
{
//stuff
}

or this
Code: Select all
if(string==0)
{
//randomness
}

I'm assuming string variables start out as 0 unless otherwise specified.

Re: if text="text"?

PostPosted: Mon Jun 13, 2011 5:53 pm
by skydereign
Well, you can do this if you want to check if it is an empty string.
Code: Select all
if(strcmp(text, "")==0)
{
    //
}


If you are checking if the string is null, you can do this, but that only applies if it is NULL (so you'd have to set it to NULL yourself).
Code: Select all
if(text==NULL)
{
    //
}