Knowing the type of data.
#3

Quote:
Originally Posted by R0
Посмотреть сообщение
pawn Код:
stock GetVarType(variable[])
{
    new length = strlen(variable), dots, letters, bool:negative = false;
    if(variable[0] == '-') negative = true;
    for(new i; i<length; i++)
    {
        if(negative == false) {
            if((variable[i] == '.') && (i>0) && i<(length-1)) dots++;
        else if((variable[i] > '9') || (variable[i] < '0')) letters++;
        }
        else {
            if((variable[i] == '.') && (i>1) && i<(length-1)) dots++;
            else if(((variable[i] > '9') || (variable[i] < '0')) && (i != 0)) letters++;
        }
    }
    if(dots == 1 && letters == 0) return 1;  // float
    else if(letters > 0 ) return 2; //string
    return 0; // integer
}
Thanks alot mate.
Reply


Messages In This Thread
Knowing the type of data. - by Ahmad45123 - 15.04.2015, 23:37
Re: Knowing the type of data. - by R0 - 15.04.2015, 23:41
Re: Knowing the type of data. - by Ahmad45123 - 15.04.2015, 23:45

Forum Jump:


Users browsing this thread: 1 Guest(s)