#include #include #include typedef struct list_elem { struct list_elem *next; int id; unsigned price; } list_elem; typedef struct customer_record { char name[32]; char address[32]; } customer_record; typedef struct large_struct { int some_integer; long array[32]; list_elem elem; customer_record customer; } large_struct; typedef struct order { customer_record *customer; list_elem *item_head; struct large_struct something_large; } order; void print_item(list_elem *print) { printf("Id: %d\n", print->id); printf("Price: %d\n", print->price); } void print_order(order *print_order) { list_elem *curr = print_order->item_head; printf("Name: %s\n", print_order->customer->name); printf("Address: %s\n", print_order->customer->address); printf("Items:\n"); while (curr != NULL) { print_item(curr); curr = curr->next; } } void init_large_struct(struct large_struct *large) { int i; large->some_integer = 45054; for (i = 0; i < 32; i++) large->array[i] = i; } void build_order() { customer_record our_customer; order our_order; list_elem first, second, third; memset(&our_order, 0, sizeof(customer_record)); first.id = 0; first.price = 137; first.next = &second; second.id = 1; second.price = 42; /* BUG2: add */ /* second.next = &third; */ third.id = 2; third.price = 61453; /* BUG3: change to NULL */ third.next = &second; /* BUG1: add */ /* our_order.customer = &our_customer; */ our_order.item_head = &first; strcpy(our_customer.name, "Mustermann"); strcpy(our_customer.address, "Unter den Linden 12a"); init_large_struct(&our_order.something_large); print_order(&our_order); } int main(void) { printf("Order management software v1.00\n"); build_order(); return 0; }