I'm validating a date and time string which must be EXACTLY of the format
yy-mm-dd hh:mm:ss
and extracting the six numeric values using sscanf.
I'm using the format string "%2u-%2u-%2u %2u:%2u:%2u" which works, but it
allows each numeric field to be either 1 or 2 digits in length. Also the man
page for sscanf says that preceeding white space before a numeric is
ignored.
But I need the input string to be EXACTLY of the above format (each numeric
is exactly 2 digits long and there is no white space) otherwise the input
string should be rejected.
What is the best way of validating the input string against an EXACT format
string and exctracting the six numeric values, or must I manually examine
every character of the input string?
yy-mm-dd hh:mm:ss
and extracting the six numeric values using sscanf.
I'm using the format string "%2u-%2u-%2u %2u:%2u:%2u" which works, but it
allows each numeric field to be either 1 or 2 digits in length. Also the man
page for sscanf says that preceeding white space before a numeric is
ignored.
But I need the input string to be EXACTLY of the above format (each numeric
is exactly 2 digits long and there is no white space) otherwise the input
string should be rejected.
What is the best way of validating the input string against an EXACT format
string and exctracting the six numeric values, or must I manually examine
every character of the input string?
Comment