get number of elements in an array

Posted By: Scorpion

get number of elements in an array - 08/12/08 15:27

hello,
can you tell me how to get the number of elements in an array in lite-c?

Thank you
Posted By: Fenriswolf

Re: get number of elements in an array - 08/12/08 15:53

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.
Posted By: Scorpion

Re: get number of elements in an array - 08/12/08 16:06

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 =/
Posted By: Trooper119

Re: get number of elements in an array - 08/13/08 13:08

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.
Posted By: Joozey

Re: get number of elements in an array - 08/13/08 17:57

I usually make use of a linkedlist as dynamic array. Otherwise I make a structure containing the array pointer and it's length.
© 2024 lite-C Forums