I have the following code, and i'm wondering how I can store each line of a text document into an array of pointers. I think im close but i'm getting a few errors.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE * fp;
char buffer[50];
int totalSize;
totalSize = 6;
int size = 0;
char * array;
fp = fopen(location,"r");
while (fgets(buffer,150,fp) != NULL)
{
array = malloc(sizeof(strlen(buffer))+1);
strcpy(array[size],buffer);
size++;
}
for (int x = 0; x < size ; x++)
{
printf("%s",array[x]);
}
free(array);
return 0;
}