sizeof(myArray[0]) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: sizeof(myArray[0]) (
/showthread.php?tid=286795)
sizeof(myArray[0]) -
MP2 - 30.09.2011
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?
AW: sizeof(myArray[0]) -
Nero_3D - 30.09.2011
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[];
Re: sizeof(myArray[0]) -
MP2 - 30.09.2011
So there's no way to find out that there's 5 values on [0], 3 on [1] etc.?