new
array1[ ][ ] = {
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // there is 9 numbers
{ 1, 2, 3, 4, 5 }, // there is 5 numbers
{ 1, 2, 3, 4, 5, 6 }, // there is 6 numbers
}
;
printf( "%d", sizeof( array1[ 0 ] ) );
sizeof(array) // First dimension
sizeof(array[]) // second dimension
sizeof(array[][]) // third dimension
new
array1[3][9] = {
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // there is 9 numbers
{ 1, 2, 3, 4, 5, 0, 0, 0, 0 }, // there is 5 numbers
{ 1, 2, 3, 4, 5, 6, 0, 0, 0 }, // there is 6 numbers
}
;
new
array1[ 3 ][ 9 ] = {
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // there is 9 numbers
{ 1, 2, 3, 4, 5, 0, 0, 0, 0 }, // there is 5 numbers
{ 1, 2, 3, 4, 5, 6, 0, 0, 0 }, // there is 6 numbers
}
;
printf( "%d", sizeof( array1 ) );
printf( "%d", sizeof( array1[] ) );
printf( "%d", sizeof( array1[][] ) );
new
index = 0,
count
;
count = /* somehow count how many numbers there is in element in array. The best way would be "sizeof( array1[ index ]", but it gives errors */
for( new i; i < count; i++ )
{
//...
}
In your case, the second dimension would always return 9, though, because that's the highest number of cells.
|
count = strlen(array1[index]); // second element
for( new i; i < count; i++ )
{
//...
}
new array1[][] = {
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, // there is 9 numbers
{ 1, 2, 3, 4, 5, 0 }, // there is 5 numbers
{ 1, 2, 3, 4, 5, 6, 0 } // there is 6 numbers
};
printf( "%d", strlen(array1[0]) );
printf( "%d", strlen(array1[1]) );
printf( "%d", strlen(array1[2]) );
new
array1[ ][ ] = {
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, // there is 9 numbers
{ 1, 2, 3, 4, 5, 0 }, // there is 5 numbers
{ 1, 2, 3, 4, 5, 6, 0 } // there is 6 numbers
}
;
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
}
;
printf( "%d", strlen( array1[ 0 ] ) ); // tag mismatch
printf( "%d", strlen( array1[ 1 ] ) ); // tag mismatch
printf( "%d", strlen( array1[ 2 ] ) ); // tag mismatch
// 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 ] ) );