For some reason this code is segfaulting for a reason I can't find out.
char *read_line(FILE *fp)
{
char *out;
int counter = 0;
char c = getc(fp);
while (c != '\n' && c != EOF)
{
*(out + counter) = c;
counter++;
c = getc(fp);
}
if (c == EOF || feof(fp))
{
return NULL;
}
*(out + counter) = '\0';
return out;
}
I have already tried running it in gdb, and that has told me that the segfault is at *(out + counter) = c;. I can't figure out what I am doing wrong, can anyone else?