tag mismatch when using strlen - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: tag mismatch when using strlen (
/showthread.php?tid=585701)
tag mismatch when using strlen -
JaydenJason - 15.08.2015
How come this gives a tag mismatch?
If I'm right, strlen returns the length of a string with an integer, how come this won't work?
Код:
GetPlayerName(playerid, testname, sizeof(testname));
if(testname[strlen(testname)] == ('s' || 'S' || 'z' || 'Z'))
Re: tag mismatch when using strlen -
Abagail - 15.08.2015
What are you trying to do? Something like this?
pawn Код:
new contain;
for(new i; i < strlen(testname); i++)
{
if(testname[i] == 'S' || testname[i] == 's' || testname[i] == 'z' || testname[i] == 'Z')
{
contain = 1, break;
}
}
Re: tag mismatch when using strlen -
JaydenJason - 15.08.2015
All I need to do is to check if the final character of the player's name ends with S or Z
Re: tag mismatch when using strlen -
Abagail - 15.08.2015
pawn Код:
new testname[128];
if(testname[strlen(testname)] == 'S')
{
printf("yes");
}
Seems to compile fine without any warnings.
Re: tag mismatch when using strlen -
Jefff - 15.08.2015
pawn Код:
new c, len = strlen(testname);
c = tolower(testname[len-1]);
if(c == 's' || c == 'z')
-
HitManxPLAYER - 15.08.2015
-_- idk how i can help u
Re: tag mismatch when using strlen -
BlackBank - 16.08.2015
Jeff kinda already explained why your code will give a error.
Quote:
Originally Posted by Jefff
pawn Код:
new c, len = strlen(testname); c = tolower(testname[len-1]); if(c == 's' || c == 'z')
|
The way you write the if-check is not right, you can't check a variable with multiple characters in this way:
PHP код:
if(testname[strlen(testname)] == ('s' || 'S' || 'z' || 'Z'))
This is the correct way (not optimized):
PHP код:
if(testname[strlen(testname)] == 's' || testname[strlen(testname)] == 'S' || testname[strlen(testname)] == 'z' || testname[strlen(testname)] == 'Z')
And the better way/optimized code is as follow, like Jefff kinda already showed as an example:
PHP код:
new character = testname[strlen(testname)];
if(character == 's' || character == 'S' || character == 'z' || character == 'Z')