hello,
i am facing a problem about reading from a file for my project.
i am using fgets() to read from my file.
i have chosen this function because i want the (char *) pointer for every line.
so i am running an infinte for loop which will break at EOF.
for each run of the for loop each line is read & the (char *) pointer for each line is obtained.
for each run of for loop i am using the same single variable for storing the char * pointer.
so i decided to use an array of char * to store all the values of char *, thus obtained by running the for loop.
now, the problem arises here... c++ wouldnt let me create an array until i give a size to it...& here the size is the no of lines in the file.
so how can i beforehand know the no of lines in the file???
i thought of a way --->by running the for loop (& using fgets) without storing anything & let a counter variable count the no of lines.
after that again i will have to use fgets.. which i do not want to do...because i want to make my program memory efficient.
may be some of u r confused. plz ask if u did not get what i am trying to say.
& thanks for reading such loooooong post!!! :)