LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

declaration of a 2 diumension array

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,

 

 

0 Kudos
Message 1 of 3
(4,199 Views)

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...

0 Kudos
Message 2 of 3
(4,198 Views)

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]);
0 Kudos
Message 3 of 3
(4,194 Views)