Hello All,
This post is regarding reading from a text file.
Background - I am trying to fill my Text struct field member char** lines with the strings from text file. However, I am having trouble simply reading from the text file itself.
I am thinking that there is an error with my while loop but am having some difficulty debugging. Anyone have an idea why my while loop is triggering a Segmentation Fault?
My code is here:
Code:
bool fill_text(Text* text, char* fileName)
{
FILE *filePtr = fopen(fileName, "r");
if(filePtr == NULL)
{
return false;
} else {
char** line = text->lines;
int max = text->maxLineCount;
int iter = 0;
while (fgets(line[iter], max, filePtr) != NULL)
{
// Printing line[iter] here to see if fgets and while are working correctly.
printf("%s\n",line[iter]);
iter++;
}
return true;
}
}