Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 24th, 2012  |  syntax: C  |  size: 0.95 KB  |  views: 2  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data