IsNumeric Problem !! Fast help
#1

Error
pawn Код:
C:\Users\CraTzy\Desktop\LVDM\gamemodes\LVDM.pwn(6262) : error 021: symbol already defined: "IsNumeric"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
The line of error
pawn Код:
stock IsNumeric(const string[])
{
    new length = strlen(string);
    if(!length) return false;
    for(new i = 0; i < length; i++)
    {
        if(string[i] > '9' || string[i] <'0') return false;
    }
    return true;
}
This is my 2nd IsNumeric but idk how to put both on 1 Stock
pawn Код:
stock IsNumeric(const string[])
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] < '0' || string[i] > '9') return 0;
    }
    return 1;
}
+Rep who help me

NVM ~FIXED ~ by myself

pawn Код:
stock IsNumeric(const string[])
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] < '0' || string[i] > '9') return 0;
    }
    new length = strlen(string);
    if(!length) return false;
    for(new i = 0; i < length; i++)
    {
        if(string[i] > '9' || string[i] <'0') return false;
    }
    return true;

}
Reply
#2

Hello!

Either you rename the first function or you delete one of them.
Reply
#3

You can't have 2 functions with the same name, You need to change the name on one of them.

I was to slow someone beat me to it
Reply
#4

as the guy above me said, rename one of them or remove.
Reply
#5

Delete both and use this
pawn Код:
IsNumeric(const string[])
{
        for (new i = 0; i < strlen(string); i++)
                if (string[i] > '9' || string[i] < '0') return 0;

        return 1;
}
Reply
#6

Why you aren't write it like this?
PHP код:
stock IsNumeric(const string[])
{
    new 
length strlen(string);
    if(!
length)return 0;
    for(new 
i;i<length;i++)
    {
        if(
string[i] > '9' || string[i] < '0')return 0;
    }
    return 
1;

Your fixed code won't be work. Take mine.
Reply
#7

Okay, I really don't see the point in flipping the if statement around lol?!
Reply
#8

Supports negative and positive numbers. It breaks the loop if false and then returns the state of the function's purpose afterwards.

pawn Код:
IsNumeric(const string[])
{
    new length = strlen(string), bool:cancel = false;
    if(!length) return false;

    for(new i = 0; i < length; i ++)
    {
        if((i == 0) && string[0] == '-' || string[0] == '+') continue;
        else if(string[i] > '9' || string[i] < '0')
        {
            cancel = true;
            break;
        }
    }

    if(cancel) return false;
    return true;
}
Reply
#9

Don't really see the need for those extensive functions. Your script will most probably use sscanf and in that case you can simply get away with:
pawn Код:
IsNumeric(const string[]) return !sscanf(string, "{d}");
Reply
#10

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Supports negative and positive numbers. It breaks the loop if false and then returns the state of the function's purpose afterwards.

pawn Код:
snip snop
if(string[i] > '9' || string[i] < '0') is the exact same as if(string[i] < '0' || string[i] > '9')

Same way that 8x5 is the same as 5x8

So both of his functions do the same thing but he just wasted time posting here
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)