mysql error
#3

Quote:
Originally Posted by Eth
Посмотреть сообщение
try this:
pawn Код:
StringNumeric(const str[])
{
    for(new i = 0,ii = strlen(str);i < ii;i++)
    {
        if(str[i] > 9 || str[i] < 0) return 0;
    }
    return 1;
}
if u'd use decimal 9 and 0, the line is the same as:

if char > TAB OR char < NULL

thats not what we want here.
we want to detect numbers, starting from
decimal 48('0') to 57('9')

the correct way to do that would be
pawn Код:
StringNumeric(const str[])
{
    for(new i = 0,ii = strlen(str);i < ii;i++)
    {
        if(str[i] > '0' && str[i] < '9') return 1;
    }
    return 0;
}
pawn Код:
printf("str: %d",StringNumeric("tms"));
output "str: 0"
pawn Код:
printf("str: %d",StringNumeric("tm5s"));
output "str: 1"

also, instead of calling a function, why not use whats already there by default.
like EOS
the head with the new condition would look like
pawn Код:
for(new i = 0;str[i]!=EOS;i++)
and it'll still work the same, even faster ^^
not that it mathers though...
Reply


Messages In This Thread
mysql error - by LazyB0y - 03.11.2014, 14:43
Re: mysql error - by Eth - 03.11.2014, 14:51
Re: mysql error - by CutX - 03.11.2014, 15:21
Re: mysql error - by LazyB0y - 04.11.2014, 07:28
Re: mysql error - by Vince - 04.11.2014, 09:30
Re: mysql error - by LazyB0y - 04.11.2014, 09:47
Re: mysql error - by Runn3R - 04.11.2014, 11:28
Re: mysql error - by LazyB0y - 04.11.2014, 11:29
Re: mysql error - by Runn3R - 04.11.2014, 11:33
Re: mysql error - by LazyB0y - 04.11.2014, 11:33

Forum Jump:


Users browsing this thread: 6 Guest(s)