I'm going to assume this is C code. Also, I'd suggest trying to find a way to redesign your code: you do
not want to be a 3-star programmer. Even ignoring readability (which should never be ignored), you'll probably have a fairly significant performance impact from the number of redirections you'll have.
I can see a number of possible problems with your
displayShowTimes function. Firstly, you are incrementing
showingCounter and then printing the contents of the array at that point, which (from your example) appears to be uninitialized memory. Have you tried swapping lines 5 and 6?
On line 6, you're trying to use the
%d format modifier for an
int*; probably, printing the address of the pointer wasn't what you meant anyway. You need another dereference.
The use of
i on line 4 could be suspect, too; a single letter identifier is a horrible choice for a global, and globals themselves should be last-resort options.
As an aside, you only need to pass a pointer to your array if you want to change the array itself, that is, perform a
realloc or
free or something of that ilk. Your function doesn't do anything like this, so passing the array itself is fine.
Here's a fixed-up version of your code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// main
int** seatCount; // please use useful variable names
seatCount = (int**)malloc(sizeof(int*) * numberShowings);
displayShowTimes(foundPtr, &showingCounter, seatCount, showID);
// ...
void displayShowTimes(node_t* foundPtr, int* showingCounter, int** seatCount, int showID) {
seatCount[*showingCounter] = &(foundPtr->movie.maxSeating[showID]);
printf("Seating: %d\n", *(seatCount[*showingCounter]));
(*showingCounter)++;
}
|
Or something like that. You may want to throw some error-checking in, too.