feat: Initial commit
This commit is contained in:
36
Laboratorio 8/Esercizio 3/Datetime.c
Normal file
36
Laboratorio 8/Esercizio 3/Datetime.c
Normal file
@@ -0,0 +1,36 @@
|
||||
// Laboratorio 8 - Esercizio 3 - Datetime.c
|
||||
// Matteo Schiff - s295565
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Datetime.h"
|
||||
|
||||
int DateTimeCompare(DateTime a, DateTime b) {
|
||||
if (a.year > b.year)
|
||||
return 1;
|
||||
else if (a.year < b.year)
|
||||
return -1;
|
||||
|
||||
if (a.month > b.month)
|
||||
return 1;
|
||||
else if (a.month < b.month)
|
||||
return -1;
|
||||
|
||||
if (a.day > b.day)
|
||||
return 1;
|
||||
else if (a.day < b.day)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DateTimeRead(DateTime * dt, FILE * fp) {
|
||||
return fscanf(fp, " %d/%d/%d %d:%d", &dt->year, &dt->month,&dt->day,&dt->hours,&dt->minutes) == 5;
|
||||
}
|
||||
|
||||
int DateRead(DateTime * dt, FILE * fp) {
|
||||
dt->hours = 0;
|
||||
dt->minutes = 0;
|
||||
return fscanf(fp, " %d/%d/%d", &dt->year, &dt->month,&dt->day) == 3;
|
||||
}
|
||||
Reference in New Issue
Block a user