how to get multiple float data in a string (on sscanf() etc)

  • Thread starter Thread starter hitbuyi
  • Start date Start date
H

hitbuyi

Guest
the problem is described as below

CString test_ytx[3] ={
"1001.21, 90.32",
"10011.21, 89.32",
"99999011.21, 89.32"};

float data[3][2] ={0.F};

I use sscanf() to convert CString test_ytx[3] to float data :

float a;
float b;
string s_omit;
int ret ;

for(i = 0; i < 3; i ++) {
ret = sscanf(test_ytx, "%f %s %f", &a, &s_omit, &b);
data[0] = a;
data[1] = b;
}

some times 10001.21 is converted to 1001.2100006, 90.32 is convert to 90.3200004, sscanf() return -1, that means conversion failure, causing collapsion of VS2015, not allow program to go on, thus my questions are

1) if I accept the conversion result, don't care the mirror difference between the original data and converted data, how to remove the collapsion of VS2015?
2) if I want the exact conversion, how to do it in MFC in case there are multiple float data in a string,the data are seperated by comma "," and space charater" "?

thanks.

Continue reading...
 
Back
Top