I am making a function that turns a list of words into an array to be used by other functions, but somehow I'm overwriting previous words. I check the memory address' and they seem different, but when I recheck once I'm done importing the words, they are all the same.
static char **array;
//takes the name of a data file and reads it into an array
static void InitDictionary(char *fileName){
//slide 36, chap 3
FILE *file;
int count,i;
char dummy[30];
file = fopen(fileName, "r");
while( fscanf(file, "%s", dummy) == 1 ){//counting at first
count++;
}
fclose(file);
array = (char**) malloc(count * sizeof(char*) );
count = 0;
file = fopen(fileName, "r");
while( fscanf(file, "%s", dummy) == 1 ){//now putting values in array
char newEntry[30];
strcpy(newEntry,dummy);
array[count] = newEntry;
printf("%d - %s : %p \n",count, array[count], &array[count]);
count++;
}
fclose(file);
for(i=0;i<count;i++)
printf("%d - %s : %p\n",i, array[i], &array[count] );
}
Thanks