Okay, so my code now looks like
Code:
typedef struct{
char text[50];
} line;
int main(int argc, char *argv[]){
f = fopen(argv[1],"r");
textfile = malloc(sizeof(line));
fgets(textfile[0].text,50,f);
int numlines = 1;
textfile = realloc(textfile,2*sizeof(line));
while(fgets(textfile[numlines].text,50,f) != NULL){
textfile = realloc(textfile,2*sizeof(line));
numlines++;
}
The way I understand realloc is that the second argument was how much additional space is to be added, but when try to add sizeof(line) it just crashed so I changed it to 2*sizeof(line)
But when I compile and run the code, it doesn't store the third line in the text file. Every other line is done fine.