• C

Project question

I am trying to begin a program for one of my classes, but I am just a blank.  I was wondering if you could give me some pointers to start me off.  Here is what it consists of:

Leap year function:  write a function that checks the year and returns 0 for a non leap year and 1 if it is.

Valid date function:  checks the year month and day, for a valid date return 1, and 0 for a non valid date.

day in year function:  returns the day of the year ex. feb 14 would be 45 depending on  a leap year.

first date function:  checks two dates entered, if any are in valid print it out.  Write out the date that comes first.

elapsed days function: enter two dates, make sure both dates are valid. ex. 1/30/2002 and 2/2/2002 four days have elapsed.

Any help you can give would be useful.
robukaps7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
first of all, you have to extract the date from an char array, and store in separate day/month/year to evaluate.
You can use strtok as a first approach:

char *datestr = "2004-07-25";   // test date
int day, month, year;
char *token;

token = strtok(datestr, "-");
year = atoi(token);
token = strtok(NULL, "-");
month = atoi(token);
token = strtok(NULL, "-");
day = atoi(token);

This is your true stating point.

To test leap year, just have to detect year every 4 years, if year is multiple of 4, the it is leaf, your can use de modulus (%) operator to do this.
To valid date, just have to make multiple ifs: if (day>=1 && day<=31), etc.
To obtain day in year, and to refine your date validation, you will need an array containing days per month. Something like:
int dpm[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31,30, 31 };
Then you have to acumulate days for every month until you reach actual month, and then sum actual day.
For date lapse, you will need the dpm array again.

Then it is your turn.
Go ahead!

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhshuklaCommented:
> To test leap year, just have to detect year every 4 years, if year is multiple of 4, the it is leaf, your can use de modulus (%) operator to do this.
not always. years in multiples of 100 have to be multiples of 400 not just 4 to be leap yrs. eg. 2000 was leap yr but 1900 wasn't.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.