I have a series of date strings in the format: “30-05-2001”
string date1 = "30-05-2001";
I would like to parse the date into Day, Month, Year. Now an easy way
of doing this would be just to call the function sscanf. But I’d like to
explore other possiblilties and from searching the web the following
function from time.h was recommended:
char *strptime(const char *buf, const char *format, struct tm *tm);
Does any anyone have experience using this function? Some short example would be
very helpful.
Thanks!
Just in case you want to understand how it works (no blackbox) or
if you need the stuff to fly (no function calls) then here are a
few tips for you:
This (untested) code is clother to the right way to do what you
wanted to do as it only does what you need to do (not more, not
less). Safe, small, simple, FAST.
If you are unsure of the date (user input) then you will have to
check for its validity (or accept the idea to live with invalid
dates in your application).