20.03.2017, 15:29
Arrfind
I was told to post it here. So posting it...
This is a very simple macro to find the element index in an array without looping making use of pawn's typless nature and it orginated from this discussion
NOTE: if we have an element value equal to 0 (as null terminator equals to 0 ) the checking stops on that index and further index would not be checked and will return -1. Therefore it can't be used with array having elements values 0.
I was told to post it here. So posting it...
This is a very simple macro to find the element index in an array without looping making use of pawn's typless nature and it orginated from this discussion
NOTE: if we have an element value equal to 0 (as null terminator equals to 0 ) the checking stops on that index and further index would not be checked and will return -1. Therefore it can't be used with array having elements values 0.
PHP Code:
#define arrfind(%0,%1) strfind(%0,{%1},false,0)
main()
{
new array[]={6,2,3,3,2340,78};
printf( "index = %d" , arrfind(array,3));//will print 2
}