title: Read a file and extract lines between two lines of specific text in C
body: <p>I am trying to extract text that is in between [HOCKEY] and [done with HOCKEY] from the following file:</p>
  
  <p><code>sport.txt</code>:</p>
  
  <pre><code>[HOCKEY]
  a=10
  b=20
  c=30
  d=45
  [done with HOCKEY]
  [SOCCER]
  a=35
  b=99
  c=123
  d=145
  [done with SOCCER]
  </code></pre>
  
  <p>With the following code I will be able to check if the line is [HOCKEY] but I am unable to record the location of 1st line and last line between [HOCKEY] and [done with HOCKEY]</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
  FILE *infile;
  char start, end;
  char *sport="[]";
  char line_buffer[BUFSIZ]; /* BUFSIZ is defined if you include stdio.h */
  int line_number,i;
  infile = fopen("sport.txt", "r");
  printf("Opened file  for reading\n");
  line_number = 0;
  while (fgets(line_buffer, sizeof(line_buffer), infile)) {
      ++line_number;
      /* note that the newline is in the buffer */
      if (line_buffer=="[HOCKEY]")
      {
      start=line_buffer;
      printf("Found start %s",start);
    }
        if (line_buffer=="[done with HOCKEY]")
      end=line_buffer;
  
      while(start&lt;end){
      printf("%c",start);
      start++;
      system("PAUSE");
      }
  }
  return 0;
  }
  </code></pre>