I want to create an array of 26 word arrays (to sort my lists of words by first letter) so I believe I allocated memory accordingly but when I try a test run and attempt to set a random word, "hi", to each spot which must have a word, it only works for the first 5 letters then returns a set fault. Pardon my code or description, I'm quite the beginner. HELP
Note: both my parameters are defined in external functions, wordArray is the array of words in a given text file, numWordsPerLetter is an integer array which holds the number of words that start with each letter of the alphabet.
char*** create_alphabetical_array(char** wordArray, int* numWordsPerLetter){
char*** alphabeticalArrays;
int i, j;
alphabeticalArrays = malloc(sizeof(char**)*26);
for (i = 0; i < 26; i++){
printf("%d\n", numWordsPerLetter[i]+1);
alphabeticalArrays[i] = malloc(sizeof(char*)*numWordsPerLetter[i]+1);
}
for (i = 0; i < 26; i++){
for (j = 0; j < (numWordsPerLetter[i]+1); j++){
printf("%d %d %d\n", i, j, numWordsPerLetter[i]+1); /* using to help debug */
strcpy(alphabeticalArrays[i][j], "hi");
}
}
return (alphabeticalArrays);
}