[prev] 87 [next]

typedef and struct (cont)

With the above TicketT type, we declare and use variables as …

#define NUM_TICKETS 1500

typedef struct {…} TicketT;

TicketT tickets[NUM_TICKETS];  // array of structs

// Print all speeding tickets in a readable format
for (i = 0; i < NUM_TICKETS; i++) {
    printf("%s %6.3f %d-%d-%d at %d:%d\n", tickets[i].plate,
					   tickets[i].speed,
					   tickets[i].d.day,
					   tickets[i].d.month,
					   tickets[i].d.year,
					   tickets[i].t.hour,
					   tickets[i].t.minute);
}