i want to extract all the integers and the corresponding time periods from the output below. After that i want to calculate the summa summarum uptime in days. The calculation is not the problem, but how can i extract the information from the bold marked part of the string?
The problem is, that the output can show up in different ways as you can see. I'm quite new in programming and i only have complicated ideas to solve this problem, like storing the data in two different arrays and then do the calculation.
I think there must be a more elegant solution? I not looking for code, i just want to get some ideas.
System uptime is 2 weeks 5 days 9 hours 4 minutes
System uptime is 1 year 25 weeks 11 days 5 hours 4 minutes
System uptime is 9 hours 4 minutes
int bla(const char *line) {
ndx = strtok(line, " ");
while (ndx != NULL) {
// extract and store data
...
ndx = strtok(NULL, " ");
}
// calculate sum of days
return days;
}
Best Regards, Georg