I have a char array
char *data[]= {\"11\", \"22\", \"33\", \"44\", \"55\"};
How can I add some extra items to it in the end? data[]=\
Here is a macro based solution for a dynamic array in C with a very nice syntax to use. Works for any data type.
#include
#include
#include
int main()
{
int* elems = NULL; /* Initialize a dynamic array. */
W_DYNAMIC_ARRAY_PUSH(elems, 1, 2, 3, 4); /* Push some elements. */
/* Iterate all elements. */
W_DYNAMIC_ARRAY_FOR_EACH(int, e, elems) {
printf("%d\n", e);
}
W_DYNAMIC_ARRAY_FREE(elems); /* Free the array only this way since there is a hidden header. */
}
The library uses Boost pre-processor library so Boost library needs to be there at build time.