To allow optional spaces before ':', replace
"%d:%d"
with
"%d :%d"
sscanf()
ignores white space where its format directives tell it to ignore, not everywhere. A whitespace character in the directive such as ' '
will ignore all white spaces. %d
as well as other integer and floating point directives will ignore leading white space. Thus a space before %d
is redundant.
C11 7,21,6,2,8 Input white-space characters (as specified by the isspace function) are skipped, unless the specification includes a [, c, or n specifier.)
Additional considerations include using %u
and unsigned
as an alternate way to not accept negative numbers. strptime()
is a common function used for scanning strings for time info.