As part of a small C program I've written, I have an insertion sort function that inserts a given string into a given array in its sorted location. I've gotten the function to work, but I'm wondering why I need to specify the second dimension for the array in the function definition to keep from getting a compilation time error. In my function, if I leave out the LONGEST_WORD macro, I get an "array has incomplete element type 'char []'" error when compiling. Everything runs smoothly when I keep it in. Could someone please explain why? Thank you!
#include <string.h>
int insertInOrder(char array[][LONGEST_WORD], char* word, int wordCount) {
int i, j, location = wordCount;
/* finds index of location to insert word; */
for (i = 0; i < wordCount; i++) {
if (strcmp(word, array[i]) <= 0) {
location = i;
break;
}
}
/* makes space for new word to be inserted, shifting all words greater than word to the right by one */
for (j = wordCount; j > location; j--) strcpy(array[j], array[j-1]);
strcpy(array[location], word); /* copies new word to its location */
return 0;
}