I have to strings with dates like '20120527' and '20120626'.
Can anyone help? i need to calculate the days between them.
thanks in advance.
I have to strings with dates like '20120527' and '20120626'.
Can anyone help? i need to calculate the days between them.
thanks in advance.
What have you done so far?
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
In time.h there is a struct tm with fields for year, month, day of month and much more. Create a struct tm for each date, parse your strings and fill in the fields required to represent the dates.
Then use difftime() to get the the time difference in seconds, just divide by seconds per day. difftime takes an epoch number not a struct tm though, so you need to convert them, you can do that with mktime().