Raised This Month: $32 Target: $400
 8% 

Some question about array..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 10-07-2015 , 10:39   Some question about array..
Reply With Quote #1

Code:
char SomeArr[][][] = {
	{
		"var1"
	},
	
	{
		"var2"
	},
	
	{
		"var3"
	}
};
What indexes will be for each of cvars? Thanks.

Last edited by ZASTRELIS; 10-07-2015 at 10:57.
ZASTRELIS is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 10-07-2015 , 11:05   Re: Some question about array..
Reply With Quote #2

This should help you to understand arrays a little bit better:
PHP Code:
for (int i=0sizeof(SomeArr); i++)
{
    
PrintToServer("SomeArr[%d]: %s"iSomeArr[i]);
    
    for (
int j=0sizeof(SomeArr[]); j++)
    {
        
PrintToServer("SomeArr[%d][%d]: %s"ijSomeArr[i][j]);
    }

It prints this:
Code:
SomeArr[0]: 
SomeArr[0][0]: char var1
SomeArr[1]: 
SomeArr[1][0]: int var2
SomeArr[2]: 
SomeArr[2][0]: char var3
If you define your array like this instead:
PHP Code:
char SomeArr[][] 
and then run the code above (without the second loop) again it looks like this:
Code:
SomeArr[0]: char var1
SomeArr[1]: int var2
SomeArr[2]: char var3
__________________

Last edited by Impact123; 10-07-2015 at 11:37.
Impact123 is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 10-07-2015 , 12:54   Re: Some question about array..
Reply With Quote #3

Thanks.. Nice tool...
ZASTRELIS is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 10-08-2015 , 11:23   Re: Some question about array..
Reply With Quote #4

What about
Code:
char sA_STD_Weapons[][] = {     {         "var1",         "var2",         "var3"     },     {         "var1_1",         "var2_1",         "var3_1"     },     {         "var1_3",         "var2_3",         "var3_3"     } };

=)

Last edited by ZASTRELIS; 10-08-2015 at 11:27.
ZASTRELIS is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 10-08-2015 , 11:39   Re: Some question about array..
Reply With Quote #5

that must be fixed as char sA_STD_Weapons[][][].

and answer is

sA_STD_Weapons[1][2] has "var3_1", sA_STD_Weapons[2][2] has "var3_3" and sA_STD_Weapons[0][0] has "var1".
__________________

Last edited by Starbish; 10-08-2015 at 11:47.
Starbish is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 10-08-2015 , 11:57   Re: Some question about array..
Reply With Quote #6

When I defined array to sA_STD_Weapons[][][] I got error
Quote:
error 018: initialization data exceeds declared size
ZASTRELIS is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 10-08-2015 , 12:04   Re: Some question about array..
Reply With Quote #7

i don't get that error
Miu is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 10-08-2015 , 12:06   Re: Some question about array..
Reply With Quote #8

if the variables isn't 3, are they amount more than 3?
Code:
char sA_STD_Weapons[][] = {     {         "var_1",         "var_N",         "var_30"     },     {         "var1_1",         "var2_N",         "var3_30"     },     {         "var1_3",         "var2_N",         "var3_30"     } };

Last edited by ZASTRELIS; 10-08-2015 at 12:08.
ZASTRELIS is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 10-08-2015 , 12:18   Re: Some question about array..
Reply With Quote #9

char g_cFileExtension[][][] = { {"mdl", "vvd", "vtx", "phy"}, {"vmt", "vtf", "", ""}, {"mp3", "wav", "wmv", "wma"} };

from my S-Downloader.

you should fill all empty if there's any empty elements
__________________
Starbish is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 10-08-2015 , 12:26   Re: Some question about array..
Reply With Quote #10

Compiler can define this array, but sizeof can't get sizes.
ZASTRELIS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:47.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode