title: How to fgets() a specific line from a file in C?
body: <p>So, I'm trying to find a way to fgets() a specific line in a text file in C, to copy the contents of the line into a more permanent buffer:</p>
  
  <p>Essentially, I was wondering if there was a way to do that without something similar to the following code:</p>
  
  <pre><code>FILE *fp;
  fp = fopen(filename, "r");
  
  char line[256];
  char * buffer;
  int targetline = 10;
  while( targetline &gt; 0)
  {
      fgets(line, 256, fp)
  }
  
  buffer =(char*)malloc(sizeof(char) * strlen(line));
  strcpy(buffer, line);
  </code></pre>
  
  <p>So basically I don't want to iterate through the file n-1 times just to get to the nth line... it just doesn't seem very efficient (and, this being homework, I need to get a 100% haha).</p>
  
  <p>Any help would be appreciated.</p>