Server Help

Non-Subspace Related Coding - strcmpi failing?

Cheese - Wed Sep 10, 2008 11:55 pm
Post subject: strcmpi failing?
on mervbot ive got a comparison:

char offenders[20]={'C','h','e','e','s','e','\0'};
if(strcmpi(offenders,m_name)||1)
{
//stuff
}

i had to add the or 1 temporarily, because i couldnt get it to succeed any way i tried.

i also tried
char offenders[20]="Cheese"
char offenders[20]="cheese"

and a whole bunch of other crap.

this uses one of the outputs of my unpacker, which is:
char m_name[20]


i cant get this to work, any ideas?


-edit-
also, tiny extra:
whats the way to have a single character, buf=='/'
i know it wont accept it, it has to be '//' or '\/' or '\\/' or some other crap...
because of the line break / in the compiler.

-edit2-
and before i forget, sscanf seems to be failing too... =/
isnt %d for a signed int?
every time i send it a negative number, it fails...

signed int temp6 = 0;
sscanf(c->final, "%d", &temp6);
k0zy - Thu Sep 11, 2008 1:11 am
Post subject:
stcmpi returns 0 if the two strings are identical.

0 equals false, so if you want something to happen if the two strings are equal you have to do:

if (!strcmpi(x,y))

or

if (strcmpi(x,y) == 0)
Dr Brain - Thu Sep 11, 2008 6:35 am
Post subject:
==0 is the preferred syntax.
Cheese - Thu Sep 11, 2008 4:16 pm
Post subject:
aargh, nonzero is supposed to be true =(


thanks =P
Samapico - Thu Sep 11, 2008 5:01 pm
Post subject:
nonzero is true, but strcmp (and related functions) don't return true or false tongue.gif
They return the difference between the two strings; so 0 means no difference. You can use it to sort strings; if it returns positive, it means one of the string is 'higher', alphabetically-speaking than the other, and a negative return value would mean the opposite.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group