naseeam
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.
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.
T is delimiter between date and time.
int year;
int month;
int day;
sscanf (iso8601_date_time_buf, "%d-%d-%d", &year, &month, &day );
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Question answered. sscanf ( ) explained very well.
Thanks for alternate solution, istringstream class.
Thanks for alternate solution, istringstream class.