This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

arrayfunction

By: a guest on Jun 24th, 2012  |  syntax: C  |  size: 0.94 KB  |  views: 17  |  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. Booking **bookingSelectPaid(Booking **booking)
  2. {
  3.     Booking **ret = malloc(sizeof(Booking*));
  4.     printf("Initial address of ret = %p\n", ret);
  5.     size_t i = 0;
  6.     int numOfPaid = 0;
  7.     while (booking[i] != NULL)
  8.     {
  9.         if (booking[i]->paid == 1)
  10.         {
  11.             printf("Paying customer! sizeof(Booking*) = %d\n", (int)sizeof(Booking*));
  12.             ++numOfPaid;
  13.             size_t newsize = sizeof(Booking*) * (numOfPaid + 1);
  14.             printf("Newsize = %d\n", (int)newsize);
  15.             Booking **temp = realloc(NULL, (size_t)newsize);
  16.             if (temp != NULL)
  17.                 printf("Expansion success! => %p sizeof(new pointer) = %d ret = %p\n", temp, (int)sizeof(temp), ret);
  18.             ret = realloc(ret, newsize);
  19.             ret[i] = booking[i];
  20.             ret[i+1] = NULL;
  21.         }
  22.         ++i;
  23.         printf("Sizeof(ret) = %d numOfPaid = %d\n", (int)sizeof(ret), numOfPaid);
  24.     }
  25.     return ret;
  26. }
clone this paste RAW Paste Data