/*
---------------------------------------------------------------------
the main purpose is speed up the app
---------------------------------------------------------------------
*/
int getVals(int *dst, char *str)
{
char tmp[12];
int j = 0;
int n = 0;
for (int i = 0; str[i]; i++) {
if (str[i] <= '9' && str[i] >= '0') {
tmp[j] = str[i];
j++;
} else {
if (j > 0) {
//form the digital
int base = 0;
for (int k = 0; k < j; k++) {
base = base * 10 + tmp[k] - '0';
}
dst[n++] = base;
j = 0;
} //if
} //else
} // for
return n;
}
/*
---------------------------------------------------------------------
the main purpose is speed up the app
---------------------------------------------------------------------
*/
inline double e_10n(int n)
{
double ary[10] = { 1., 0.1, 0.01, 0.001, 0.0001, \
0.00001, 0.000001, 0.0000001, 0.00000001, 0.000000001 };
return ary[n];
}
int getVals(float *dst, char *str)
{
char tmp[12];
int j = 0;
int n = 0;
int f = 0;
for (int i = 0; str[i]; i++) {
if (str[i] <= '9' && str[i] >= '0' || str[i] == '.') {
tmp[j] = str[i];
j++;
if (str[i] == '.')
f = j;
} else {
if (j > 0) {
//form the digital
int base = 0;
for (int k = 0; k < j; k++) {
if (tmp[k] == '.')
continue;
base = base * 10 + tmp[k] - '0';
}
f = f ? j - f : 0;
dst[n++] = base * e_10n(f) ;
f = 0;
j = 0;
} //if
} //else
} // for
return n;
}
字符串转数字
最新推荐文章于 2022-11-07 14:55:09 发布