27 Oct, 2012, triskaledia wrote in the 1st comment:
Votes: 0
if((skill_table[sn].name == "bone armor") && (ch->pcdata->learned[sn] > 99))
af.modifier = -25;
else
af.modifier = -20;


magic2.c: In function 'spell_bone_armor':
magic2.c:244: warning: comparison with string literal results in unspecified behavior

I was wondering what is wrong with my if statement that is causing it to have a warning. I have this on a couple other spells also.
27 Oct, 2012, KaVir wrote in the 2nd comment:
Votes: 0
Use strcmp(), not ==.
27 Oct, 2012, Realmsofvalor wrote in the 3rd comment:
Votes: 0
Hi,

The comparison method you are using checks the memory address of what the variables point to, NOT a literal string interpretation. So it will definitely not work because skill_table[sn].name and a string you made, "bone armor", do not point to the same memory address. What you want to do is use a string comparison function, like strcmp().

Example:
if ((!strcmp(skill_table[sn].name, "bone armor")) && (ch->pcdata->learned[sn] > 99))

strcmp returns a 0 (false) value if both strings are the same, thus the ! to turn it 'true' in this instance. Keep in mind strcmp is case-sensitive.
29 Oct, 2012, triskaledia wrote in the 4th comment:
Votes: 0
How exactly does strcmp work? Compare the first part against the second part to check for a true or false statement?
29 Oct, 2012, Realmsofvalor wrote in the 5th comment:
Votes: 0
strcmp compares string1 to string2.

String1 in this instance is 'skill_table[sn].name', and string2 is the "bone armor".

Strcmp compares each ascii letter in the strings and stops when the letters differ. If both strings are identical, it returns a 0 (would be considered False). It is standard C function.
0.0/5