Advertisement
Guest User

Untitled

a guest
Jun 24th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1.  
  2.  
  3. #include "bookings.h"
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. int main() {
  10.  
  11.   Booking *antti = bookingConstruct("Antti", 1, 10);
  12.   bookingPrint(stdout, antti);
  13.   bookingPay(antti);
  14.  
  15.   Booking *raimo = bookingConstruct("Raimo", 2, 20);
  16.   Booking *petteri = bookingConstruct("Petteri", 3, 30);
  17.  
  18.   bookingPay(petteri);
  19.   // Raimo didn't pay for his room
  20.  
  21.  
  22.   // An array of Booking pointers. The last element is NULL.
  23.   Booking *bookings[] = {antti, raimo, petteri, NULL};
  24.   // The function returns an array {antti, petteri, NULL}
  25.   Booking **paidBookings = bookingSelectPaid(bookings);
  26.   printf("----\n");
  27.   for (int i = 0; paidBookings[i] != NULL; ++i)
  28.     bookingPrint(stdout, paidBookings[i]); // Prints the paid bookings to standard output
  29.   for (int i = 0; paidBookings[i] != NULL; ++i)
  30.     bookingDestruct(paidBookings[i]);
  31.   free(paidBookings);
  32.  
  33.   bookingDestruct(raimo);
  34.   bookingDestruct(antti);
  35.   bookingDestruct(petteri);
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement