04-10-2015 09:07 AM
Hello,
I'm tryning to decare an array of 18 line and 10 colomn
char *stabMesures [19][10];
i want that each cell have a maximum size
what i can add to this declaration?
Many Thanks,
04-10-2015 09:12 AM
What is an array of lines? Probably your line is a character array, so finally you will end up with a three-dimensional character array (18 lines each say 40 characters maximum times 10 columns). But then I do not understand what you call your cell...
04-10-2015 09:20 AM
If each element of your array is to be a string with a fixed maximum length, you can define it as a 3-dimensional array:
#define MAX_LENGTH 7 char stabMeasures[18][10][MAX_LENGTH + 1]; // add 1 for the trailing null
If the elements will be different lengths, you can use dynamic allocation:
char* stabMeasures[18][10]; stabMeasures[0][0] = malloc(16 * sizeof(char)); sprintf(stabMeasures[0][0], "Element 0, 0"); stabMeasures[0][1] = malloc(24 * sizeof(char)); sprintf(stabMeasures[0][1], "Longer element 0, 1"); ... ... free(stabMeasures[0][0]); free(stabMeasures[0][1]);