title: How to print the text from a file if the line number is given?
body: <p>I want to give input as line number and get output as the corresponding text for that line number in a text file.</p>
  <p><strong>Sample text file:</strong></p>
  <pre class="lang-none prettyprint-override"><code>Hi this is Stefen  
  Hi How are you
  </code></pre>
  <p><strong>Example input:</strong></p>
  <pre class="lang-none prettyprint-override"><code>Enter the line number:2
  </code></pre>
  <p><strong>Expected Output:</strong></p>
  <pre class="lang-none prettyprint-override"><code>Hi How are you
  </code></pre>
  <p><strong>My program is:</strong></p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      FILE *fp;
      fp = fopen(&quot;sample.txt&quot;, &quot;r&quot;);
      if (fp == NULL) {
          perror(&quot;Unable to open the file\n&quot;);
          exit(1);
      }
      char buf[256];
      
      while (fgets(buf, sizeof(buf), fp) != NULL) {
          printf(&quot;%s\n&quot;, buf);
          print(&quot;~~~~\n&quot;);
      }
              
      fclose(fp);
              
      return 0;
  }
  </code></pre>
  <p><strong>Output I got</strong>:(The entire file with the separator <code>~~~~</code> below each line)</p>
  <pre><code>Hi this is Stefen
  ~~~~
  Hi How are you
  ~~~~
  </code></pre>
  <p>Can anyone please tell me how to do this?</p>