Create in_array
#2

pawn Код:
stock in_array(array[], value, size = sizeof array)
{
    for(new i; i < size; i++)
    {
        if(array[i] == value) return 1;
    }
    return 0;
}
Why? Because sizeof is resolved at compile time, not run time. You have to pass the size when you call the function. You might be interested with custom iterators from y_iterate/foreach. But that's for bigger dynamic arrays. Also, you could simply return index at the same time, with -1 when not found.
Reply


Messages In This Thread
Create in_array - by Noliax8 - 24.02.2014, 19:01
Re: Create in_array - by Misiur - 24.02.2014, 19:04

Forum Jump:


Users browsing this thread: 1 Guest(s)