tag mismatch when using strlen
#1

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'))
Reply
#2

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;
        }
    }
Reply
#3

All I need to do is to check if the final character of the player's name ends with S or Z
Reply
#4

pawn Код:
new testname[128];
    if(testname[strlen(testname)] == 'S')
    {
        printf("yes");
    }
Seems to compile fine without any warnings.
Reply
#5

pawn Код:
new c, len = strlen(testname);
c = tolower(testname[len-1]);
if(c == 's' || c ==  'z')
Reply
#6

-_- idk how i can help u
Reply
#7

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'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)