DIGIT-ARC read-only archive · snapshot: July 23, 2026

[C] Program to find period of days

6 posts · originally from https://geek.digit.in/community/threads/c-program-to-find-period-of-days.131586/

T
technique_007 Original post #1
Sep 10, 2010 at 10:48 PM
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
S
Sep 11, 2010 at 6:36 AM
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
T
Sep 11, 2010 at 7:55 PM
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 at 12:31 AM
Re: help with a program

you are doing the right way, um in the way the question has asked you to do
T
Sep 12, 2010 at 11:54 AM
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 ??
S
Sep 12, 2010 at 12:15 PM
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