Raised This Month: $12 Target: $400
 3% 

Multidimensional array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-16-2014 , 11:14   Multidimensional array
Reply With Quote #1

Why it prints like

Quote:
1. 1 First
2. 2 First
3. 3 First
I want

Quote:
1. 1 First
2. 1 Second
3. 1 Third
4. 1 Fourth
PHP Code:
#define MAX_CATEGORIES 3

new const g_iMaxNames[MAX_CATEGORIES] = { 42};

new const 
g_szNames[][] =
{
    { 
"1 First""1 Second""1 Third""1 Fourth" },
    { 
"2 First""2 Second" },
    { 
"3 First""3 Second""3 Third""3 Fourth""3 Fiveth" }
};

// In menu

    
for (new 0g_iMaxNames[Selection]; i++)
    {
        new 
szItem[256];
        
formatex(szItemcharsmax(szItem), "%s"g_szNames[Selection][i]) // Know that problem is here, but I don't get it..

        
menu_additem(MenuszItem""0);
    } 

Last edited by ~Ice*shOt; 11-16-2014 at 13:41.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-16-2014 , 13:36   Re: Multidimensional array
Reply With Quote #2

That can't even compile . . . also, that is a 3 dimensional array so you need to add a dimension to the declaration.
__________________
fysiks is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-16-2014 , 13:41   Re: Multidimensional array
Reply With Quote #3

Why it can't? I understand, that it's not full code but it compiles at all.
How should look this line if I add 3rd dimension?
PHP Code:
formatex(szItemcharsmax(szItem), "%s"g_szNames[Selection][i
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-16-2014 , 13:50   Re: Multidimensional array
Reply With Quote #4

You don't need to chagne that line (if I'm not mistaken), you only need to add a third dimension to the declaration of the array.
__________________
fysiks is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-16-2014 , 14:02   Re: Multidimensional array
Reply With Quote #5

There is how it looks added one more dimension

PHP Code:
new const g_szNames[][][] =
{
    { 
"1 First""1 Second""1 Third""1 Fourth""" },
    { 
"2 First""2 Second""""" },
    { 
"3 First""3 Second""3 Third""3 Fourth""3 Fiveth" }
}; 
It is possible to prevent that ""? Because without them I am getting

Quote:
error 052: multi-dimensional arrays must be fully initialized
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Old 11-16-2014, 14:13
~Ice*shOt
This message has been deleted by YamiKaitou. Reason: duplicate post
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-16-2014 , 14:30   Re: Multidimensional array
Reply With Quote #6

Quote:
Originally Posted by ~Ice*shOt View Post
It is possible to prevent that ""? Because without them I am getting
No, you must always fully initialize an array
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply


Thread Tools
Display Modes

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 19:33.


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