All I'm doing is initiating a double pointer in c (char*) to hold my array of strings. I pass this variable (char* array_strings) into another function which should open a file and create an array of strings representing each line of the file, but for some reason when I return from the function the variable array_strings is null.
int main(void) {
char **array_strings;
char *book_file = "book.txt";
delimitByNewline(book_file, array_strings);
return 1;
}
//delimit file
void delimitByNewline(char *book, char **array) {
int count = 0;
int i = 0;
char c;
int size = fileLines(book);
srand(time(NULL));
char **ret_array = (char **)malloc(sizeof(char *) * size);
FILE *bk = fopen(book, "rt");
if(!bk) {
perror("fp");
exit(1);
}
char *line = (char *)malloc(sizeof(char)*60);
while ((c = fgetc(bk)) != EOF) {
line[i] = c;
i++;
if(c == '\n') {
ret_array[count] = line;
line = (char *)malloc(sizeof(char) * i);
count++;
i = 0;
}
}
fclose(bk);
array = ret_array;
free(line);
free(ret_array);
}