Reputation: 125
Is it possible in anyway to recursively create a given number of arrays in C with predetermined length? I want to experiment with arrays for a clustering project and would be really practical if i could do this.
Upvotes: 0
Views: 94
Reputation: 145899
Yes it is possible, allocate an array of pointers then allocate all the arrays:
T **array = malloc(rows * sizeof *array);
for (i = 0; i < rows; i++)
{
array[i] = malloc(cols * sizeof **array);
}
it create rows
numbers of array. Each array is an array of cols
numbers of T
.
Upvotes: 2