LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how can deal with array result

I use cvi  write a dll,it should be return the result as below:

   7.47854E-2,7.47854E-2,7.47854E-2,7.47854E-2,7.47854E-2,7.52150E-2,7.47854E-2,7.52150E-2,7.52150E-2,7.52150E-2,7.47854E-2

how can I deal with it like this:

  a[0]= 7.47854E-2

  a[1]=7.47854E-2

and so on,thanks

0 Kudos
Message 1 of 4
(3,268 Views)
Hi,
What is the data type of that returned result? Is it a string or an array?
Maybe you have to make this tranformation manually.

Yunquan Bao
AE
NI Shanghai
0 Kudos
Message 2 of 4
(3,234 Views)

Looks like a string of readings in ASCII coming from an instrument like a 34970A multimeter or similar.

 

You can get the  readings into a string (array of char with trailing NUL (0)), then use strtok function in C standard library with "," token to parse the string into substrings that you can then scan with something like  

 

double dReading;

char * szValue;

 

for (int i = 1, I <= numreadings; i++) {

  if (i == 1) {

    szValue = strtok (szReadings, ",");

  }

  else {

    szValue = strtok (NULL, ",");

  }

   sscanf (szReading, "%lf", &myArray[i-1]);

}  // end, for

 

0 Kudos
Message 3 of 4
(3,204 Views)

The smiley faces are supposed to be closing parentheses , and the for statement should be

 

for (int i = 1; i <= numReadings; i++)

 

 and I'm assuming the use of C99 extension allowing the declaration of ablock scope variable other than at the beginning of the block.

 

or just query the instrument for one reading at a time and fill the array that way.

 

Menchar

0 Kudos
Message 4 of 4
(3,187 Views)