sizeof 2D array
#8

pawn Code:
// array
new
    Float:array1[ ][ ] = {
        { 1.1, 9.8, 2.5, 0.0 }, // there is 3 numbers
        { 1.6, 5.1, 0.0 }, // there is 2 numbers
        { 1.2, 5.3, 6.0, 5.3, 0.0 } // there is 4 numbers
    }
;
// function
stock len( Float:array[ ] )
{
    new
        i = 0,
        count
    ;
    while( array[ i ] != 0.0 )
    {
        count++;
        i++;
    }
    return count;
}
// printing
printf( "%d", len( array1[ 0 ] ) );
It works perfect, but I think there should be a better solution. This is unoptimized, because I should store the lenght in another array in the first time checking, then check if it was checked and if it was, return lenght from another array to don't use while loop again . Why in PAWN sizeof can't simply work like sizeof( array[ 0 ] )?
Reply


Messages In This Thread
sizeof 2D array - by zgintasz - 04.07.2012, 12:40
Re: sizeof 2D array - by Vince - 04.07.2012, 12:57
Re: sizeof 2D array - by zgintasz - 04.07.2012, 13:09
Re: sizeof 2D array - by Vince - 04.07.2012, 13:17
Re: sizeof 2D array - by zgintasz - 04.07.2012, 13:19
Re: sizeof 2D array - by Vince - 04.07.2012, 13:27
Re: sizeof 2D array - by zgintasz - 04.07.2012, 13:33
Re: sizeof 2D array - by zgintasz - 05.07.2012, 08:41

Forum Jump:


Users browsing this thread: 4 Guest(s)