Campbell Ritchie wrote:That I think is C++ code because of the bool keyword, not C.
C introduced bool albeit after C++. It is a 'typedef' and one needs to include <stdbool.h> for it to be usable.
Campbell Ritchie wrote:I presume the == and != operators are overloaded on Strings.
Actually, C does not have a native
string type. In C, one uses an array of characters terminated by the NUL character to hold strings. In C++, one has the string class that comes with member functions (substr is one of them) and overloaded operators.
Campbell Ritchie wrote:I suspect the greatest overhead is in the format time function. What complexity does that run in?
The code posted by the OP does not need any while loops. Also, the OP could use a function that does the reverse of 'format_time' (i.e., one that takes the formatted string representation of the time and returns the integral equivalent.