How to fetch first two bytes from the string “DDMMYYHHMMSS” and fill the below structure.
mytime.tm_sec = SS; // Seconds (0-59)
mytime.tm_min = MM; // Minutes (0-59)
mytime.tm_hour = HH; // Hours (0-23)
mytime.tm_mday = YY; // Day of Month (1-31)
mytime.tm_mon = MM; // Month (0-11)
mytime.tm_year = DD; // Year (no. of years since 1900)
I’m assuming this is homework, so I won’t give you the full answer.
Let’s split this problem into bits.
1) Given a string, do you know how to extract a sub-string? E.g., can you figure out how to accomplish this:
Hint: Look up
strncpy().2) Once you’ve figured that out, do you know how to convert a string of digits to a number? E.g., can you accomplish this:
Hint: Look up
sscanf()&atoi().At this point, combining those two techniques should be straightforward. By all means ask more if you need more help.