Browse Source Download (without any required ccan dependencies)
darray
Generic resizable arrays
Joey Adams <joeyadams3.14159@gmail.com>
darray is a set of macros for managing dynamically-allocated arrays. It removes the tedium of managing realloc'd arrays with pointer, size, and allocated size.
#include <ccan/darray/darray.h>
#include <stdio.h>
int main(void) {
darray(int) numbers = darray_new();
char buffer[32];
for (;;) {
int *i;
darray_foreach(i, numbers)
printf("%d ", *i);
if (darray_size(numbers) > 0)
puts("");
printf("darray> ");
fgets(buffer, sizeof(buffer), stdin);
if (*buffer == '\0' || *buffer == '\n')
break;
darray_append(numbers, atoi(buffer));
}
darray_free(numbers);
return 0;
}
MIT