I want to test the "time_str" to see if it's has the correct format. The format should be "##,##,##"
int hr, min, sec;
if sscanf( time_str, "%i %*[,] %i %*[,] %i", &hr, &min, &sec) !=3)
If a user enters for "time_str" something like:
02x,05,05 or 02,05x,05
the conversion will fail based on the rules in the sscanf(which is good!).
The problem I'm having is if the user enter something like this in the third position (i.e. sec):
02,05,05x <-- bad data in the 3rd position
the sscanf will be successful. How can I catch the fact that non-numeric data is in the 3rd position?
PS - I know I could probably switch over to using char definitions for the hr, min, sec and then test etc., but is there a way to sscanf this the way I have it presented?
Thanks!
int hr, min, sec;
if sscanf( time_str, "%i %*[,] %i %*[,] %i", &hr, &min, &sec) !=3)
If a user enters for "time_str" something like:
02x,05,05 or 02,05x,05
the conversion will fail based on the rules in the sscanf(which is good!).
The problem I'm having is if the user enter something like this in the third position (i.e. sec):
02,05,05x <-- bad data in the 3rd position
the sscanf will be successful. How can I catch the fact that non-numeric data is in the 3rd position?
PS - I know I could probably switch over to using char definitions for the hr, min, sec and then test etc., but is there a way to sscanf this the way I have it presented?
Thanks!