Size of 2D Array
#1

Hi guys, I have a problem with 2D array. I can't use sizeof because it's 2D array. Array contains male and female skins, so it looks

Код:
new const _HRP_Skinovi[2][] = 
{
	// MUЉKI SKINOVI
	{
		1, 2, 3, 4, 5, 6, 7, 8, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 32, 33,
		34, 35, 36, 37, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 57, 58, 59, 60, 66, 67, 72, 73, 78, 79, 82,
		83, 84, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
		114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 132, 133, 134, 135, 136,
		137, 142, 143, 144, 146, 147, 153, 154, 156, 158, 159, 160, 161, 162, 168, 170, 171, 173, 174, 175,
		176, 177, 179, 180, 182, 183, 184, 185, 186, 187, 188, 189, 200, 202, 206, 208, 209, 210, 212,
		213, 217, 220, 221, 222, 223, 227, 228, 229, 230, 234, 235, 236, 239, 240, 241, 242, 247, 248, 249,
		250, 252, 254, 258, 259, 261, 253, 264, 268, 269, 270, 271, 272, 273, 289, 290, 291, 292, 293,
		294, 295, 296, 297, 299, 303, 304, 305
	},

	// ЋENSKI SKINOVI
	{
		9, 10, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54, 55, 56, 64, 65, 69, 75, 76, 77, 85, 87, 88, 89, 90, 91,
		93, 129, 130, 131, 138, 139, 140, 141, 145, 148, 150, 151, 152, 157, 169, 172, 190, 192, 193, 194,
		195, 196, 197, 198, 199, 201, 207, 211, 214, 215, 216, 218, 219, 224, 225, 226, 231, 232, 233, 237, 238,
		243, 244, 245, 246, 251, 256, 257, 263, 298 		
	}
};
Here's sizeof. I want to get total number of skins in index 0(male skins)

Код:
printf("%d aaa",  sizeof(_HRP_Skinovi[0]));
Sizeof makes these errors

Quote:

E:\Silvio\Projekti\Pawn\GameModovi\Od nula\Haswell RolePlay\gamemodes\HRP.pwn(633) : error 001: expected token: "]", but found "-integer value-"
E:\Silvio\Projekti\Pawn\GameModovi\Od nula\Haswell RolePlay\gamemodes\HRP.pwn(633) : warning 215: expression has no effect
E:\Silvio\Projekti\Pawn\GameModovi\Od nula\Haswell RolePlay\gamemodes\HRP.pwn(633) : error 001: expected token: ";", but found "]"
E:\Silvio\Projekti\Pawn\GameModovi\Od nula\Haswell RolePlay\gamemodes\HRP.pwn(633) : error 029: invalid expression, assumed zero
E:\Silvio\Projekti\Pawn\GameModovi\Od nula\Haswell RolePlay\gamemodes\HRP.pwn(633) : fatal error 107: too many error messages on one line

Is here any way for use sizeof on 2D array with undefined 2nd index?
Reply
#2

To get the size of the second dimension you normally use:
PHP код:
sizeof(array[]) 
But what you want to do is impossible because a dimension only has one size. Indices that you don't explicitly assign a value get an implicit value of 0. So the compiler sees this as:
PHP код:
... 2562572632980000000000, ... 
Up until the amount of male skins.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
To get the size of the second dimension you normally use:
PHP код:
sizeof(array[]) 
But what you want to do is impossible because a dimension only has one size. Indices that you don't explicitly assign a value get an implicit value of 0. So the compiler sees this as:
PHP код:
... 2562572632980000000000, ... 
Up until the amount of male skins.
Is here any way to do same thing without a problem? Or I need to split arrays on male and female skins?
Reply
#4

You want to get the size of it, but it will ALWAYS give the size of the bigger one, you can't get smaller one's size unless you use strlen.

Since EOS is 0 and you don't have 0 in any of those arrays, I think you can use strlen(array[0]), give it a try maybe ?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)