14 int je_prestupny(
unsigned int rok);
15 unsigned int pocet_dnu(
unsigned int mesic);
16 int generuj_datumy(
const char *nazev,
unsigned int pocet);
17 int precti_datumy(
char *nazev);
18 DATUM maximum(
char *nazev);
23 generuj_datumy(
"datumy.dat", 100);
24 precti_datumy(
"datumy.dat");
25 m = maximum(
"datumy.dat");
26 printf(
"\nNejpozdejsi datum je: %u. %u. %u\n", m.den, m.mesic, m.rok + MIN_ROK);
31 int je_prestupny(
unsigned int rok)
34 return (rok % 400 == 0);
36 return (rok % 4 == 0);
39 unsigned int pocet_dnu(
unsigned int mesic)
41 const static int pocet[] = { 31, 28, 31, 30, 31, 30,
42 31, 31, 30, 31, 30, 31
45 return pocet[mesic - 1];
50 int generuj_datumy(
const char *nazev,
unsigned int pocet)
56 fw = fopen(nazev,
"wb");
60 srand((
unsigned) time(NULL));
61 for (i = 0; i < pocet; i++) {
67 rok = (rand() % (MAX_ROK - MIN_ROK + 1)) + MIN_ROK;
68 mesic = (rand() % 12) + 1;
69 max_den = pocet_dnu(mesic);
70 if ((mesic == 2) && (je_prestupny(rok)))
72 den = (rand() % max_den) + 1;
76 d.rok = rok - MIN_ROK;
77 zapsano = fwrite(&d,
sizeof(
DATUM), 1, fw);
83 if (EOF == fclose(fw))
88 int precti_datumy(
char *nazev)
94 fr = fopen(nazev,
"rb");
102 precteno = fread(&d,
sizeof(
DATUM), 1, fr);
103 printf(
"%u. %u. %u\n", d.den, d.mesic, d.rok + MIN_ROK);
104 }
while (precteno == 1);
106 if (EOF == fclose(fr))
111 DATUM maximum(
char *nazev)