Reputation: 47
I need to extract hours, minutes and seconds from a string formatted as e.g: "00:53:12" to variables a, b and c.
How would I go about this in C?
Thanks in advance!
Upvotes: 2
Views: 386
Reputation: 3029
Use standard function strptime:
strptime(timestr,"%H:%M:%S", ret)
Upvotes: 1
Reputation: 80761
You can use strptime
struct tm tm;
if (strptime("00:53:12", "%H:%M:%S", &tm) != NULL)
printf("hour: %d; minutes: %d; seconds: %d;\n",
tm.tm_hour, tm.tm_min, tm.tm_sec);
Upvotes: 7