# include # include /* strtor -- convert a string of real numbers into a real array Description: ------------ If the input string is blank(s), this routine will return 0. If there are characters other than digits, decimal point, comma, semi-colon, or slash in the input string, this routine will issue an error message. Date Author Description ---- ------ ----------- 09-May-1996 J.-C. Hsu Adapt from the SPP code strtor.x 10-Feb-2000 Phil Hodge Replace exit (2) with return (0). */ int strtor (char *str, float arr[]) { int ip; /* index of the string to be searched */ int n, i, ipx; int done; double rval; char tmp[100]; n = 0; ip = 0; ipx = 0; done = 0; while (!done) { if (str[ip] == ',' || str[ip] == ';' || str[ip] == '/' || str[ip] == '\0') { for (i = 0; i < (ip-ipx); ++i) tmp[i] = str[ipx+i]; tmp[ip-ipx] = '\0'; rval = atof(tmp); if (!rval && (ip-ipx) != 0) { printf ("illegal input string '%s'\n", str); return (0); } arr[n] = (float) rval; ++n; ipx = ip + 1; } if (str[ip] == '\0') break; ++ip; } return (n); }