typedef struct Date_t { int day; char month[4]; int year; } Date ; typedef struct Person_t { char* name; int height; Date birth; } Person ; : Person p ; Person* pp=&p; p.birth.year = 1994 pp->birth.year = 1994; pp->birth->year ? 11
Slide 12
birth Date Date typedef struct Person_t { char* name; int height; Date* birth; } Person ; : Person p ; Person* pp=&p; p.birth->year = 1994 pp->birth->year = 1994; : p Person Date ! ? 12
Slide 13 year); } 13">
: typedef struct Date_t { int day; char month[4]; int year; struct Date_t* next; } Date ; : int main() { Date dt1, dt2, *pdt ; dt1.day = 31 ; dt1.year = 1992 ; strcpy(dt1.month,DEC); dt2.day = 1 ; dt2.year = 1993 ; strcpy(dt2.month,JAN); pdt = &dt2; dt1.next = &dt2; printf ("Year in dt1: %d\n Year in dt2: %d\n ",dt1.year, (dt1.next)->year); } 13
Slide 14
year dt2 : dt2.year = 1994; pdt year = 1994; (dt1.next) year = 1994; next -dt2 ? 14 pdt 31 DEC 1992 1 JAN 1993 ? dt1 dt2
Slide 15
: , : 15
Slide 16 day = day; tmp->year = year; strcpy(tmp->month,month); tmp->next = top ; top = tmp; } print_date_list(top); return 0; } 16 ? ?">
int main() { Date *top = NULL, *tmp = NULL ; int day, year ; char month[4]; while (scanf("%d %s %d", &day,month, &year) != EOF){ tmp = (Date*) malloc(sizeof(Date)); if (tmp == NULL) { free_date_list(top); exit(0); } tmp->day = day; tmp->year = year; strcpy(tmp->month,month); tmp->next = top ; top = tmp; } print_date_list(top); return 0; } 16 ? ?
Slide 17
void free_date_list(Date *top){ Date *current=top, *tmp; while (current != NULL) { tmp=current; current=current->next; free(tmp); } 17
Slide 18 day, current ->month, current ->year); current = current->next ; } 18">
void print_date_list(Date *top){ Date * current = top; while (current != NULL) { printf("%d %s %d\n", current ->day, current ->month, current ->year); current = current->next ; } 18
Slide 19 day = day ; tmp->year = year ; strcpy(tmp->month,month); tmp->next = top ; top = tmp; } print_date_list(top); return 0; } int main() { Date *top = NULL, *tmp = NULL ; Date date; while (scanf("%d %s %d", &date.day,date.month, &date.year) == 3){ tmp = (Date*) malloc(sizeof(Date)); if (tmp == NULL) { free_date_list(top); exit(0); } *tmp = date; tmp->next = top ; top = tmp; } print_date_list(top); free_date_list(top); return 0; }">
19 int main() { Date *top = NULL, *tmp = NULL ; int day,year ; char month[4]; while (scanf("%d %s %d", &day,month, &year) != EOF){ tmp = (Date*) malloc(sizeof(Date)); if (tmp == NULL) { free_date_list(top); exit(0); } tmp->day = day ; tmp->year = year ; strcpy(tmp->month,month); tmp->next = top ; top = tmp; } print_date_list(top); return 0; } int main() { Date *top = NULL, *tmp = NULL ; Date date; while (scanf("%d %s %d", &date.day,date.month, &date.year) == 3){ tmp = (Date*) malloc(sizeof(Date)); if (tmp == NULL) { free_date_list(top); exit(0); } *tmp = date; tmp->next = top ; top = tmp; } print_date_list(top); free_date_list(top); return 0; }
Slide 20
: . events: 1 JAN 404 Last gladiator competition 6 MAY1889 Eiffel tower opens 21 NOV 1794 Honolulu harbor discovered 1 JAN 1852 First US public bath opens 2 MAR 1969 First takeoff of the Concorde 6 MAY1915 Orson Welles is born 6 MAY 1626 Manhattan purchased for 1000$ 2 MAR 1969 First landing of the Concorde 20
Slide 21
: > important_dates events enter date: 2 MAR 1969 First takeoff of the concorde First landing of the concorde enter date: 23 NOV 1999 Nothing special 21
Slide 22
22 date events list next date events list next Historical Date date events list next event description historicalDateList
Slide 23
#define MAX_LINE_LENGTH 100 typedef struct Date_t { int day; char month[4]; int year; } Date; 23
HistoricalDate* readEvents(FILE* inputFIle) { char description[MAX_LINE_LENGTH]; Date date ; HistoricalDate *firstHistoricalDate =NULL, *currentHistoricalDate = NULL; Event *event = NULL; while (readEvent(inputFIle,&date, description)) { currentHistoricalDate = find(firstHistoricalDate,date) ; if (currentHistoricalDate == NULL) { /* in case the date doesn't exist add this date to be the first in the list */ currentHistoricalDate = allocateHistoricalDate(date); if (currentHistoricalDate == NULL) { return NULL ; } currentHistoricalDate->next = firstHistoricalDate ; firstHistoricalDate = currentHistoricalDate ; } event = allocateEvent(description); if (event == NULL) { return NULL; } event->next = currentHistoricalDate->eventList; currentHistoricalDate->eventList = event; } return firstHistoricalDate ; } 32
Slide 33
int main(int argc, char* argv[]) { FILE* inputFile = NULL; HistoricalDate* historicalDateList= NULL, *historicalDate = NULL; Date date; if (argc != 2) return 1 ; if ((inputFIle = fopen(argv[1],r))==NULL) return 2 ; historicalDateList = readEvents(inputFile); /*creating the list*/ fclose(inputFile); if (historicalDateList == NULL) return 3 ; printf(enter date:); while (readDate(stdin,&date)) { historicalDate = find(historicalDateList,date) ; if (historicalDate == NULL) printf (Nothing special\n); else printEvents(historicalDate->eventList); printf(enter date:); } return 0; } 33