I am writing a function to dynamically allocate a string array from my dictionary file that will be accessed through command line arguments. I keep getting segmentation fault 11 and cannot figure out why
int
allocateArray(int count)
{
int i;
char **array;
char **argv;
char *fileName = argv[1];
FILE *fp = fopen(fileName, "r");
count = countTokens(argv);
array = malloc(sizeof(char *) * count);
if (array == 0)
{
fprintf(stderr, "memory allocation failed\n");
exit(1);
}
for(i = 0; i < count; i++)
{
array[i] = malloc(count);
}
for (i = 0; i < count; i ++)
{
fscanf (fp,"%s", array[i]);
}
free(array);
fclose(fp);
return **array;
}