1. ## date comparing

Hi,

Input: Names and born dates of persons
Output: Oldest person and his/here born date

How to do this? I'm new at this so be gentle

thx

2. a) If A is born in 1940 and B in 1941 then A is older.
else if years are the same
b) If A is born in September and B in October then A is older.
else if months are the same
c) If A is born on the 13th and B on the 14th then A is older.
else they are both the same age

Hope this gives you an idea.

But you really should try to formulate some ideas, e.g how you are going to represent data, how you are going to search the persons etc, post some code and ask more specific questions.

3. thx for fast replay

I need to use array if I have more than two names.

I know how to make this in delphi, so I need someone
who can explain me how arrays, dates, etc works in C.

4. If you only want to display data for one person you don't need arrays. Just store the data for the currently oldest person and discard younger ones.

For dates may-be you can use something from the <time.h> header, but the data for a person might be as simple as a struct containing a string (name) and three integers (year, month, day).

5. time_t holds dates from 0 to max. 0 I think starts at January 1, 1970. So if you convert the dates into time_t then comparing dates is a simple unsigned long (time_t) comparison.

6. I'm trying but something isn't right...
Code:
```#include <stdio.h>
#include <time.h>
int main()
{
double dif;
time_t t1, t2;
dif=difftime(t1,t2));
clrscr();
printf("First date:");
scanf("&#37;d",t1);
printf("Second date:");
scanf("%d",t2);
printf("\nThe difference between dates is: ", diff);
}```
what do I need here?

7. Well, first of all, your call to difftime is done BEFORE you read the time variables from the user, so that won't work.

Also, it won't compile, because you have one variable "dif" that is declared, then printing a "diff" which is undeclared, so I guess you have to fix that.

Just to clarify, if you use "Microsoft Excel", you can declare a calculation, and then change the variables that the calculation relates to afterwards, and get the new value out of it. C, C++ and most other programming languages, the calculation is done with the values the variable have at the time, and no matter what other changes you do later, the value stays the same. So you need to make sure the variables are "filled in" before you use them for a calculation.

--
Mats

8. Nor can you use &#37;d to scan directly into a time_t.

First you need to use fgets() to read a line.
Then use strptime to parse the line and fill in a tm struct with the parsed information. If you don't have strptime, then you need to roll your own to do the same thing.
Then you use mktime() to turn your tm struct into a time_t.
Finally, having done that twice, you have two time_t variables which you can difftime()

9. Originally Posted by matsp
Just to clarify, if you use "Microsoft Excel", you can declare a calculation, and then change the variables that the calculation relates to afterwards, and get the new value out of it. C, C++ and most other programming languages, the calculation is done with the values the variable have at the time, and no matter what other changes you do later, the value stays the same. So you need to make sure the variables are "filled in" before you use them for a calculation.
Ah so that's what's going on in the minds of a few posters recently.
I was baffled as to what confusion of ideas made people think that they could do the calculations before they have read in the data! A quantum computer with reversal of cause and effect perhaps?!?!

10. Originally Posted by iMalc
Ah so that's what's going on in the minds of a few posters recently.
I was baffled as to what confusion of ideas made people think that they could do the calculations before they have read in the data! A quantum computer with reversal of cause and effect perhaps?!?!
Of course I have no idea what the people writing such code are actually thinking - but the Excel example has crossed my mind before.

--
Mats

11. Ok. Maybe I posted wrong code... I have tried diff and dif (typing mistake).
Also, I declare diff=difftime(... after input, also didn't work. I will try SALEM's
post. I think it would we correct... thx...