I'm trying to create an expandable (indexed) array in C for String Elements, similar to say an ArrayList<String>
in Java.
I googled around and found an implementation of an indexed expandable C-array and I was wondering if someone could help me adjust this for strings.
Note - I don't mind imposing a maximum length for the strings
Here is the code -
http://happybearsoftware.com/implementing-a-dynamic-array.html
Any help would be greatly appreciated.
ArrayList's in Java are complex data structures based on object oriented programming, while arrays in C programming language are simply indexed chains
of allocated memory of certain lengths.
The only way to access an element in C programming language array is to give it's index, which is used to compute the address
of variable in this array you wish to access.
example:
If character[11] is an array of char
, each char variable takes 1 byte, you wish to access 5th element of array characters
, the address of this element will be compute like that: 5*1+(address of the first element).
If you wish to use more complex data structures in C programming language you will have to implement it. Here is a good place to start: