Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 1,088 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get number of elements in an array #221167
08/12/08 15:27
08/12/08 15:27
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
hello,
can you tell me how to get the number of elements in an array in lite-c?

Thank you

Re: get number of elements in an array [Re: Scorpion] #221171
08/12/08 15:53
08/12/08 15:53
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Hello,

obviously there is no adequate solution for this in Lite-C.
In C-Script it was possible to get an arrays length with the length property (was not documented though), but this doesn't work in Lite-C anymore.

As a workaround you could use the first array index to store its length or you could use the last index to store some kind of 'terminator'.
However, it's not exactly brilliant...

You could also implement your own array structures. By making them dynamic you could at least kill two birds with one stone.

Re: get number of elements in an array [Re: Fenriswolf] #221172
08/12/08 16:06
08/12/08 16:06
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
I created an ENTITY* array dynamically to be exactly(with pointer to a pointer stuff..whäää)

And because the 'array' is just a pointer I can't use sizeof()

So I think I have to save the array size separately =/

Re: get number of elements in an array [Re: Scorpion] #221313
08/13/08 13:08
08/13/08 13:08
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline
User
Trooper119  Offline
User

Joined: Apr 2004
Posts: 516
USA
I usually make a function that goes with making a new entry into my dynamic array, with that is a persistent counter that goes with the array, and that would be referenced for the number you want.

Hope this helps.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: get number of elements in an array [Re: Trooper119] #221369
08/13/08 17:57
08/13/08 17:57
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
I usually make use of a linkedlist as dynamic array. Otherwise I make a structure containing the array pointer and it's length.


Click and join the 3dgs irc community!
Room: #3dgs

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1