Eina inline array of strings

This example creates an inline array of strings, adds some elements, and then prints them. This example is based on Basic array usage and Eina inline array usage.

We start with some variable declarations and eina initialization:

int
main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
const char* strings[] = {
"helo", "hera", "starbuck", "kat", "boomer",
"hotdog", "longshot", "jammer", "crashdown", "hardball",
"duck", "racetrack", "apolo", "husker", "freaker",
"skulls", "bulldog", "flat top", "hammerhead", "gonzo"
};
char **str, **str2;
Eina_Inarray *iarr;
int i;
eina_init();
eina_init
EINA_API int eina_init(void)
Initializes the Eina library.
Definition: eina_main.c:291
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
_Eina_Inarray
Inline array structure.
Definition: eina_inarray.h:225

We then create the array much like we did on Eina inline array usage :

iarr = eina_inarray_new(sizeof(char *), 0);
eina_inarray_new
EINA_API Eina_Inarray * eina_inarray_new(unsigned int member_size, unsigned int step)
Creates a new inline array.
Definition: eina_inarray.c:342

The point is this example significantly differs from the first eina inline array example. We are not going to add the strings themselves to the array since their size varies, we are going to store a pointer to the strings instead. We therefore use `char**` to populate our inline array:

for (i = 0; i < 20; i++){
str = (char **)(&strings[i]);
eina_inarray_push(iarr, str);
}
eina_inarray_push
EINA_API int eina_inarray_push(Eina_Inarray *array, const void *data)
Copies the data as the last member of the array.
Definition: eina_inarray.c:411

The source for this example: eina_inarray_02.c