Season's greetings! I have a function that prints out the contents of a char** that is being used as an array to store a number of strings. The is declared like this:
char** commandArray = (char**)malloc(historySize);
where historySize is a global int set to 8, for now. The array is populated with commands that the user enters, in sort of a circular queue. There are more than a couple places where I may want the contents of the buffer printed out, so I made a function. Ideally, the function takes in a reference to commandArray and loops through it, printing out what it contains. Now, I have to say that pointers and references are not my strong point, so I'm not really sure if I'm doing things correctly. The function looks like this:
/* prints the contents of the history buffer */
void printHistory(char*** historyBuff)
{
/* a counter for the loop */
int loopIdx = 0;
for (loopIdx = 0; loopIdx < historySize; loopIdx++)
{
/* print the current history item */
printf ("\nhistoryBuff[%i] = %s\n", loopIdx, *historyBuff[loopIdx]);
fflush(stdout);
}
}
I'm passing my char** into the function like this:
printHistory (&commandArray);
As it stands now, everything compiles fine, but when the program prints the history, the function hangs somewhere in the loop and does not print out what is in the char**. SO, my question to you is this: Am I passing commandArray properly, am I declaring the function correctly, and am I dereferencing it the right way in the function?
Thank you in advance for any and all help or suggestions!
-Ben