Help to Generalize my C Program.

This is a discussion on Help to Generalize my C Program. within the C Programming forums, part of the General Programming Boards category; I have a C Program that allows a user to enter two dates, compares the two, then prints out which ...

Help to Generalize my C Program.

I have a C Program that allows a user to enter two dates, compares the two, then prints out which date is earlier than the other. I would now like to generalize the program so that i can have the user enter as many dates as they want until they enter 0/0/0 which will signal the stopping point. Then i just need the program to print only the earliest date out of all of the dates the user enters. Not too sure how to accomplish this. Here is my starting code:

It might help to first write a program which is basically the same but simpler -- write a program that asks the user for simple integers until the user enters the special integer -999. Afterwards, print the smallest integer that was entered. If you can make the program I just described, then you basically do the same thing for the date problem (except with the date you have three items to compare).

Also it might help if you have a compare function that works similarly to integers. For example, if you have integers x and y, then the following is how it is usually done:

It is nice if we can basically do the same for a user defined type like a date. The conventional way is to make a comparison function which returns -1 if the first object is less than the second one, 0 if they are the same, and 1 if the first object is greater than the second object. The advantage is that the above integer test looks similar:

Hmm... maybe the number of functions in time.h is intimidating for novice users. Maybe for learning purposes, design your own simple solution, and then come back to see how you can do something similar using the functions above.