Provided that you don't have to load a file with a size in the order of some GB's, I suggest that you try something like this:
- check the size of the file
- allocate a chunk of dynamic memory as large as needed to contain the whole contents of the file
- load the contents of the file in the allocated memory
- scan the resulting string in order to count the total number of '\n' characters contained in the allocated memory (which equal to the number of lines)
- allocate a chunk of memory containing space for a vector of pointers to char as long as the number of lines
- store the pointer to the first character of the loaded string, then scan the loaded string again looking for each '\n' character; whenever you do find one, do two things: a. put a '\0' terminator in place of the '\n' and b. store the index of the next character into the next pointer to char of your vector
When the process is done, you should have a vector containing pointers to char, each of which pointing to the very start of one line taken from the file and zero terminated. You then should be able to access those strings by using the pointers stored in the vector with simple zero-based indexes. Of course, it would be a good thing isolating the mechanism I just described in a dedicated subroutine. I could provide sample code, and you surely could grasp the mechanism in a much easier way, but looks like providing complete sample code is forbidden in this forum.