strlower
#1

What's wrong with this?
PHP код:
strlower(string[])
{
    for(new 
i=0i<MAX_PLAYER_NAMEi++)
    {
        
string[i] = tolower(string[i]);
    }
    return 
string;

When I types amalm, it prints "#Lњamalm"

What should I do?
Reply
#2

If I'm not mistaking, tolower only lowercases one letter, so this comes in handy:
pawn Код:
#define UpperToLower(%1) for ( new ToLowerChar; ToLowerChar < strlen( %1 ); ToLowerChar ++ ) if ( %1[ ToLowerChar ] > 64 && %1[ ToLowerChar ] < 91 ) %1[ ToLowerChar ] += 32
credits to original author of that define.

Try this:
pawn Код:
strlower(string[])
{

    UpperToLower(string);
    return string;
}
Reply
#3

Also you could use
pawn Код:
for(new i=0; string[i] != EOS; i++)
Watch out for accidental arrays though
Reply
#4

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Also you could use
pawn Код:
for(new i=0; string[i] != EOS; i++)
Watch out for accidental arrays though
When I use that, it prints "<#L�amalm"
Reply
#5

What is the meaning of this ??
Did you make a stock with this function ?
If this is the code that you made the function with add
PHP код:
stock 
before the nae of the function.
Reply
#6

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
What is the meaning of this ??
Did you make a stock with this function ?
If this is the code that you made the function with add
PHP код:
stock 
before the nae of the function.
Read the post I made a few hours ago: https://sampforum.blast.hk/showthread.php?tid=558834

I also had the same doubt.

But, still my problem isn't fixed. Anybody help me.
Reply
#7

With your code, it gives me spaces instead of litters
test code:
pawn Код:
public OnPlayerText(playerid, text[])
{
    SendClientMessage(playerid, -1, strlower(text));
    return 0;
}
stock strlower(string[])
{
    for(new i; i<strlen(string); i++) string[i] = tolower(string[i]);

    return string;
}
Those work, tested, one returns the string and one doesn't.
pawn Код:
#define strlower(%1)        for(new i; i<strlen(%1); i++) %1[i] = tolower(%1[i])

public OnPlayerText(playerid, text[])
{
    strlower(text);
    return 1;
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    SendClientMessage(playerid, -1, strlower(text));
    return 0;
}
stock strlower(string[])
{
    new tempstring[MAX_PLAYER_NAME];

    for(new i; i<strlen(string); i++) tempstring[i] = tolower(string[i]);

    return tempstring;
}
Reply
#8

If those weird characters appeared on the end of the string it woulbe be understandable - typical overflow. However they are appearing at the beginning of the string. What argument are you passing to this function? Is it some substring of inputtext?
Reply
#9

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
With your code, it gives me spaces instead of litters
test code:
pawn Код:
public OnPlayerText(playerid, text[])
{
    SendClientMessage(playerid, -1, strlower(text));
    return 0;
}
stock strlower(string[])
{
    for(new i; i<strlen(string); i++) string[i] = tolower(string[i]);

    return string;
}
Those work, tested, one returns the string and one doesn't.
pawn Код:
#define strlower(%1)        for(new i; i<strlen(%1); i++) %1[i] = tolower(%1[i])

public OnPlayerText(playerid, text[])
{
    strlower(text);
    return 1;
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    SendClientMessage(playerid, -1, strlower(text));
    return 0;
}
stock strlower(string[])
{
    new tempstring[MAX_PLAYER_NAME];

    for(new i; i<strlen(string); i++) tempstring[i] = tolower(string[i]);

    return tempstring;
}
I gets these errors with the second code:
Quote:

E:\San Andreas Roleplay Cops And Robbers\gamemodes\SARCR.pwn(789) : error 029: invalid expression, assumed zero
E:\San Andreas Roleplay Cops And Robbers\gamemodes\SARCR.pwn(789) : error 029: invalid expression, assumed zero
E:\San Andreas Roleplay Cops And Robbers\gamemodes\SARCR.pwn(789) : warning 215: expression has no effect
E:\San Andreas Roleplay Cops And Robbers\gamemodes\SARCR.pwn(789) : error 017: undefined symbol "i"
E:\San Andreas Roleplay Cops And Robbers\gamemodes\SARCR.pwn(789) : fatal error 107: too many error messages on one line

These lines are the stock Userpath
Reply
#10

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
With your code, it gives me spaces instead of litters
test code:
pawn Код:
public OnPlayerText(playerid, text[])
{
    SendClientMessage(playerid, -1, strlower(text));
    return 0;
}
stock strlower(string[])
{
    for(new i; i<strlen(string); i++) string[i] = tolower(string[i]);

    return string;
}
Those work, tested, one returns the string and one doesn't.
pawn Код:
#define strlower(%1)        for(new i; i<strlen(%1); i++) %1[i] = tolower(%1[i])

public OnPlayerText(playerid, text[])
{
    strlower(text);
    return 1;
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    SendClientMessage(playerid, -1, strlower(text));
    return 0;
}
stock strlower(string[])
{
    new tempstring[MAX_PLAYER_NAME];

    for(new i; i<strlen(string); i++) tempstring[i] = tolower(string[i]);

    return tempstring;
}
Third code worked

Thank you very very much, bro

You are the best

rep++;
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)