mardi 15 avril 2014

C: est-ce possible de créer automatiquement un certain nombre de tableaux ? -Débordement de pile


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.




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.



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.



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.


Related Posts:

0 commentaires:

Enregistrer un commentaire