title: read line by line in the most efficient way *platform specific*
body: <p>i am looking for a most efficient way to read a text file.</p>
  
  <p>considering every possible bit of advantage, like the advantage of:</p>
  
  <p>code will be platform specific windows OS</p>
  
  <p>and with the fact i am writing a specific for current CPU etc'..</p>
  
  <p>*don't mind it's not multi platform.</p>
  
  <p><strong>just plain performance issue</strong></p>
  
  <p>how could i code the fastest way, reading each line of a text file into a struct ? </p>
  
  <p>say the struct is :</p>
  
  <pre><code>typdef struct _FileL{
   uint lidx;
   char* lncontent;
  } FileL;
  </code></pre>
  
  <p>i was thinking of something like:</p>
  
  <p>passing a dynamic array of <code>FileL</code> above and the path to the file
  what would be the most efficient way to populate and return a collection of lines of the given file ?</p>
  
  <pre><code>getFileLines(char* fullPath, FileL** fileLines){
      uint linesCount = 0;// total lines
      uint curLnIndex = 0;// lines counter
  
      FILE* srcFL; // will hold the source file using passed fullPath
  
      // now read file into memory 
      //that is the only way i could think of 
      //to be able to assign lineCount used to calculate the array length
      //and also the fastest way is  to read the whole file into memory (?)
  
      srcFL = fopen(fullPath,"r"); // or open() instead of fopen() ?
  
     // problem:
     // assigning lineCount somehow would cost the time of reading
     // and might aswell just populate it and already store to array..
     // so what is the workaround ?
  
    *fileLines =(FileL*) malloc (linesCount * sizeof(FileL));
     FileL* CurLn = *fileLines;
  
     while(curLnIndex != linesCount){
       char* TmpLnCont;
       //read line into TmpLnCont..
       CurLn-&gt;lidx = curLnIndex ;
       CurLn-&gt;lncontent = (char*)malloc(sizeof(TmpLnCont));
       strcpy(CurLn-&gt;lncontent, TmpLnCont);
     }
  }
  </code></pre>
  
  <p>how would it be more efficient approach ? </p>
  
  <p><strong>Edit :</strong></p>
  
  <p>i wanted to update the question as i would like to address the issue of efficiency: the most efficient way down to the detail of scanning the file for each line, is it the only way char by char, how to avoid a call to function on each char ... anything to max the performance of looping on each line meaning to get to the definition of a line efficiently ...</p>