01-21-2009 12:19 AM
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
01-23-2009 12:19 AM
01-26-2009 11:30 PM
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
01-27-2009 12:43 PM
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