LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

array declaration problem

Hallo everybody,
 
I don't know why it worked, perhaps the form of declaration is not in the correct style.
 
What I need:
an 2D array with the size of 10x10 for int values with the name "speed"
 
Perhaps somebody can give me an example, how it works in LabWindows/CVI 6.0.
 
Thanks
Florian
0 Kudos
Message 1 of 5
(3,227 Views)

Why not simply speed[10][10]? This code:

int i, j, speed[10][10];

for (i = 0; i < 10; i++) {
  for (j = 0; j < 10; j++) {
    speed[i][j] = (i + 1) * (j + 1);
  }
}

will produce this result:

 
speed[x][y]->   0   1   2   3   4   5   6   7   8   9
      |        --------------------------------------
      V
      0 |       1   2   3   4   5   6   7   8   9  10
      1 |       2   4   6   8  10  12  14  16  18  20
      2 |       3   6   9  12  15  18  21  24  27  30
      3 |       4   8  12  16  20  24  28  32  36  40
      4 |       5  10  15  20  25  30  35  40  45  50
      5 |       6  12  18  24  30  36  42  48  54  60
      6 |       7  14  21  28  35  42  49  56  63  70
      7 |       8  16  24  32  40  48  56  64  72  80
      8 |       9  18  27  36  45  54  63  72  81  90
      9 |      10  20  30  40  50  60  70  80  90 100


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 5
(3,215 Views)

Ok, thx.

But how can I write to / read only one element?

Thx for answering this basic c program problem. Sorry *gg*

 

Florian

0 Kudos
Message 3 of 5
(3,209 Views)
You can use every single element of the array exactly as a normal variable:
 
write to it
   speed[row][col] = 1275;
 
fill by scanning a string
   strcpy (a, "123456");
   sscanf (a, "%d", &speed[1][1]);
 
display on a control
    SetCtrlVal (panel, contrl, speed[4][5]);
 
or embed in strings
    sprintf (msg, "Speed = %d", speed[3][4]);
 


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,203 Views)
Thanks, I think now I will find a solution.
0 Kudos
Message 5 of 5
(3,199 Views)