My program begins by opening a dictionary file, the first line of which contains the number of words in the dictionary. If I print the words immediately after scanning them into the arrays, they appear fine, but if I later examine a previous entry, I can see it has been partially overwritten, usually after the first four letters. I think it's my mistake lies in my memory allocation, but I'm not sure.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int binsearch(char* word,int size,char* dictionary);
int main(void)
{
FILE* dict;
dict = fopen("dictionary.in","r");
int words;
fscanf(dict,"%d",&words);
int i;
char** dictionary[words];
for(i=0;(i<words);i++)
{
dictionary[i] = malloc( 30 * sizeof(char*));
fscanf(dict,"%s",&dictionary[i]);
printf("%s\n",&dictionary[i]);
printf("%s\n",&dictionary[i-1]);
}
printf("%s",&dictionary[5000]);
free(*dictionary);
free(dictionary);
fclose(dict);
return 0;
}