sizeof(myArray[0])
#1

I need to get how many numbers are in each row, they aren't all the same.

pawn Code:
new myArray[][] = {
{1, 2, 3, 4, 5},
{1, 2, 3},
{6, 9},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
};
I want to be able to do 'sizeof(myArray[0])' and get 5, but I get:

Quote:

error 001: expected token: "]", but found "-integer value-"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero

All on this line:

pawn Code:
new myVar = sizeof(myArray[0]);
So annoying. I must be mis-understanding how arrays work or something. What can I do to get around this?
Reply
#2

array dimensions must always have the same size
if you dont declare a size the compiler gets it, its always the size of the biggest row

because of that you can only get the size of the dimensions with sizeof
pawn Code:
const stock
    Array[][] = {
        {1, 2, 3, 4, 5},
        {1, 2, 3},
        {6, 9},
        {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    },
    SizeD1 = sizeof Array,
    SizeD2 = sizeof Array[];
Reply
#3

So there's no way to find out that there's 5 values on [0], 3 on [1] etc.?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)