list is supposed to be an array of pointers, so hopefully I declared that correctly.
This function is supposed to read lines of text and each line of text should have a pointer pointing to it so that I can sort them.
What I don't understand is when I read in the text do I have to save each line to an array and then my array of pointers would point to that array? I'm thinking each line should be in an array because then I could print out the whole line afterward. Is that the best way to do it?
char *read_file( istream *infile, data_t *lines_ptr ){
char *list = new char[LIST_SIZE];
char ch;
int line = 0;
// starts out true so that the first line of text is stored
bool char_after_newline = true;
while ( (ch = infile->get()) != EOF ){
cout << ch;
// Executes if there is a new line and then fills an array with
// the characters
if ( char_after_newline == true ){
// NEED HELP HERE
line++;
}
// This if-else statement marks whether a new line is coming up
if ( ch == '\n' ){
char_after_newline = true;
} else {
char_after_newline = false;
}
}
// Save the number of lines for use in the calling function
*lines_ptr = line;
return list;
}
Thanks for any help.