3 registered members (AndrewAMD, mciwjd545, 1 invisible),
787
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Multidimensional Array of STRINGS
#386344
11/01/11 22:06
11/01/11 22:06
|
Joined: Dec 2010
Posts: 66 München (Germany)
dice
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 66
München (Germany)
|
Hi everyone, I already know how to create an one-dimensional Array of Strings:
myString = malloc((int) sizeof(STRING*) * 5);
for(int i = 0; i < 5; i++)
myString[i] = str_create("");
But how to create a multidimensional Array with this method? I tried sth like this:
myString = malloc((int) sizeof(STRING*) * 5);
for(int i = 0; i < 5; i++)
myString[i] = str_create("");
for(int i = 0; i < 5; i++) {
myString[i] = malloc((int) sizeof(STRING*) * 5);
for(int k = 0; k < 5; k++)
myString[i][k] = str_create("");
}
But it wont work... Help me please ;D GreetZ dice!
Last edited by dice; 11/01/11 22:06.
|
|
|
Re: Multidimensional Array of STRINGS
[Re: sivan]
#397000
03/13/12 09:30
03/13/12 09:30
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
If your version of 3DGS supports it, you are better of using SYS_malloc() and SYS_free() instead of malloc() and free().
They have EXACTLY the same syntax and usage, but are somewhat 'managed' by the engine.
I cant remember exactly, but I think they do more error-checking, and they get automatically 'cleaned-out' by the engine on exit. ... I think ... Its been a while...
FYI: By following the same pattern, you can do 3, 4, or more dimensional arrays too. eg: STRING**** data; //referenced by (((data[w])[x])[y])[z]=0;
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Multidimensional Array of STRINGS
[Re: EvilSOB]
#397002
03/13/12 09:47
03/13/12 09:47
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
thanks, I use it not for strings, but works. I know and always use sys_malloc because it's really safe, if no realloc is needed afterwards... and maybe I'm now able to simulate an n-dimesnional space travel (I completely forgot what I learnt about n-dimensional space mathematics at university...) I just put a post at blame the manual to add an example of this situation, because I think it is really useful!
|
|
|
Re: Multidimensional Array of STRINGS
[Re: sivan]
#397005
03/13/12 09:59
03/13/12 09:59
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
BTW, I guess you are already aware, it works on basically any data type.
I mostly use it for entities, longs, and custom structs.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Multidimensional Array of STRINGS
[Re: PriNova]
#407155
09/07/12 14:40
09/07/12 14:40
|
Joined: Sep 2012
Posts: 74 Niedersachsen, Germany
PriNova
Junior Member
|
Junior Member
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
|
i only get it to work if i define the string array with pre-defined dimensions like:
STRING** mystring[5][5]
beccause in this example i know the dimensions already, but how to do with dynamic arrays i don't know.
Last edited by PriNova; 09/07/12 14:42.
|
|
|
|