IsNumeric Explanation
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
The brackets are there to stop the warning, because you are right that you don't normally have an assignment in loops, but in this case you do. As for why it stops, strings are "NULL" terminated. That means that after all the characters you see there is a special character, which is empty. The loop keeps going while the current character is not empty.

Anyway, if you want to use YSI, and not custom functions (frankly a silly position but there we go), there is an "isnumeric" function in there already (a better one than both posted here btw):

pawn Код:
/**--------------------------------------------------------------------------**\
<summary>isnumeric</summary>
<param name="str[]">String to check</param>
<returns>
    -
</returns>
<remarks>
    Checks if a given string is numeric.
</remarks>
\**--------------------------------------------------------------------------**/


stock isnumeric(str[])
{
    P:7("isnumeric called: \"%s\"", str);
    new
        i;
    while (IS_IN_RANGE(str[i], '0', '9' + 1)) ++i;
    //while ((ch = str[i++])) if (!('0' <= ch <= '9')) return 0;
    return !str[i];
}
I never said I didn't want to use custom functions. I said I don't like taking random code that people post online. If someone posts code for something, I usually try to rewrite it better and differently so I understand it and so I'm not just taking peoples code.

So does the loop use the assignment statement like it would use "i < MAX_PLAYERS" and when it hits "NULL", it stops? I'm just confused as to how the assignment also acts as a comparison.

Quote:
Originally Posted by Pulsefire
Посмотреть сообщение
Once you run into something that's not numeric loop stops. 123A34342 as string function will loop until it finds that A and then return 0 comes into the place.
Like I clearly stated in the post, suppose the the string IS numeric. Why would it stop?

Quote:
Originally Posted by Ihateyou
Посмотреть сообщение
it just loops each character in the string and checks if its a number between 0 and 9? whats so complicated?
I didn't ask what it did. Your reply clearly shows how well you read.
Reply


Messages In This Thread
IsNumeric Explanation - by admiralspeedy - 23.07.2014, 05:35
Re: IsNumeric Explanation - by Pulsefire - 23.07.2014, 06:08
Re: IsNumeric Explanation - by Threshold - 23.07.2014, 06:55
Re: IsNumeric Explanation - by Ihateyou - 23.07.2014, 07:57
Re: IsNumeric Explanation - by admiralspeedy - 23.07.2014, 15:57

Forum Jump:


Users browsing this thread: 1 Guest(s)