# [C] Program to find period of days



## technique_007 (Sep 10, 2010)

please help with this C program

write a program that finds number of days between a period entered by user.Check invalidity also.


I tried to write the program but it became too long considering fact that months had to be converted into days depending whether they had 30 or 31 days and years also converted into days depending whether i was leap  yr or not.....Am I going the right way or wandering off ????

Help in both the cases


----------



## sakumar79 (Sep 11, 2010)

*Re: help with a program*

you should make use of time.h functions available like difftime and time_t type - See The GNU C Library - Date and Time for reference in time functions

Arun


----------



## technique_007 (Sep 11, 2010)

*Re: help with a program*

@sakumar
thx for reply, but we have been taught only upto loops(to be specific 'for' loop) till now.
So I dont think time.h function is required to be used...

can u suggest a simpler way..plzz


----------



## Liverpool_fan (Sep 12, 2010)

*Re: help with a program*

you are doing the right way, um in the way the question has asked you to do


----------



## technique_007 (Sep 12, 2010)

*Re: help with a program*

@liverpool fan

kk.....but i am stuck at this point only....

can u suggest as how to write all this stuff  ??


----------



## sakumar79 (Sep 12, 2010)

*Re: help with a program*

Create functions for each task - checking validity of a date, leap year check, etc and simplify your main function by calling each separately... 

One possibility is you can create a function that returns the number of days a date is after 1/1/0001 AD and then take the difference of the result for the two dates...

Arun


----------

