SHARE
TWEET

arrayfunction

a guest Jun 24th, 2012 18 Never
  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. }
RAW Paste Data
Top