Saving mobile number as string
#1

So i made a system where im saving players mobile numbers to strings like pMobile[50] and now when im using /call command how do i check if he entered text into second parameter or number ? /call jasfojsaofp should return SCM(playerid, -1, "Enter number, not text u fool"); and /call 00908978 return SCM(playerid, -1, "You entered wrong number");
Reply
#2

if you are using sscanf, you can just use it like this:
Код:
COMMAND:call(playerid, params[])
{
    new number;
    if(sscanf(params, "i", number)) return SendClientMessage(playerid, -1, "Enter number, not text u fool");
    //some other stuff
    return 1;
}
if you don't use sscanf, then you should start using sscanf.
If you don't want to (then you are a fool) you can use this:
Код:
COMMAND:call(playerid, params[])
{
    if(!isNumeric(params)) return SendClientMessage(playerid, -1, "Enter number, not text u fool");
    //some other stuff
    return 1;
}
if you don't have a isNumeric function already, you can use e.g. this
Код:
stock bool:isNumeric(const string[])
{
    if(string[0] != EOS) {
        for(new i = -1; ; ) {
            switch(string[++i]) {
                case '+', '-', '.', '0'..'9': continue;
                case EOS: return true;
                default: return false;
            }
        }
    }
    return false;
}
Reply
#3

pawn Код:
IsNumeric(const string[])
{
    for(new i = 0, l = strlen(string); i <= l; i++)
    {
        if(!('0' <= string[i] <= '9')) return 0;
    }
    return 1;
}
Use this to check the parameter.
Reply
#4

Ty guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)