How can I convert a command line argument in the format of HH:MM:SS thats a string into a time_t type? The only solutions I've found have been for C++ and to convert time_t into string but not the other way around in C.
Thanks.
edit: I need to implement it without string.h
I'm trying to convert a command line argument and a string (e.g."13:32:41" and "13:40:35") into a time_t format so I can use difftime(tm1,tm2) to get the difference.
Would the below work?
time_t string_to_time(const char* time) {
struct tm tm = {0};
sscanf(time, "%H:%M:%S", &tm.tm_hour,&tm.tm_min, &tm.tm_sec);
time_t t=mktime(&tm);
return t;
}