This does not make an array of strings:
char **array;
array = malloc(bufsize * sizeof(char));
There are plenty of resources that describe how to do this. eg. How to create a dynamic array of strings.
Essentially, you need to allocate space for the array, then allocate space for each the strings, a standard way might be:
char **arrayOfStrings;
unsigned int numberOfElements = 20, sizeOfEachString = 100;
arrayOfStrings = malloc(numberOfElements * sizeof(char*));
for (int i = 0; i < numberOfElements ; i++)
arrayOfStrings[i] = malloc(sizeOfEachString * sizeof(char));
As a further note, for your while
loop:
while (getline(&line, &bufsize, fp)) {
Is sufficient. Getline will return 0 once you have finished your file. Read this.