I saw this answer (you can use the minor example in Ideone there, it's equivalent), so I wrote the function below to do the job, but it will stop when reading the dot before the decimal digits and will treat pi like 3 and 14. How to change the code to extract the real number? I do not care about speed or memory usage, I just want to do the job.
float extract_number(char* str) {
char* p = str;
while (*p) {
if (isdigit(*p)) {
long val = strtol(p, &p, 10);
printf("%ld\n", val);
return val;
} else {
p++;
}
}
return -1.0;
}
Here is the str
I am working with:
Initializing data structure(s) took 149.898690000 seconds wall clock time.