sizeof 2D array
#6

Hmm, in that case you should be fine with strlen, I suppose. Should work as long as you don't have any 0 somewhere in the middle of your element (e.g. 1, 2, 0, 3) as that is regarded as the null terminator and will affect the return of strlen.

pawn Code:
count = strlen(array1[index]); // second element
for( new i; i < count; i++ )
{
    //...
}
Edit: Just tested that, but it does require a null terminator. This will produce the output you're looking for:

pawn Code:
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]) );
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: 1 Guest(s)