Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Using sscanf ( ), how to extract date from buffer that contain combined date and time ?

iso8601_date_time_buf is pointer to const char.  It's length is Twenty bytes.  It contains combined date and time in format:   YYYY-MM-DDTHH:MM:SS
T is delimiter between date and time.  

int year;
int month;
int day;
				
sscanf (iso8601_date_time_buf, "%d-%d-%d", &year, &month, &day );

Open in new window


A delimiter is followed by first two %d.  Do I need a delimiter after 3rd %d because day is in the middle of the buffer.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just in cae I misunderstood your question: Using 'sscanf()', it's necessary to parse all the variable parts of your input string, otherwise you'll run into trouble.
Or, a bit more general, independant from the parsing method you choose (and there are plenty): You have to parse all variable fields in order to achieve a correct result, since otherwise all methods are doomed to fail at these very fields by definition.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam

ASKER

Question answered.  sscanf ( ) explained very well.

Thanks for alternate solution, istringstream class.