title: Segmentation Fault while Reading from File
body: <p>I am trying to print last 10 lines of a file. Following is my code, but it is giving a segmentation fault due to fscanf. While running with gdb the fault reads : vfscanf.c: No such file or directory.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      FILE *fp = fopen("microfile.txt","r");
      char *c[10];
      int idx = 0;
      cout&lt;&lt;fp&lt;&lt;"\n";
      while(!feof(fp))
      {
          if(idx&lt;10)
          {
              fscanf(fp,"%s",c[idx]);
              idx++;
          }
          else if(idx==10)
          {
              for(int i=0;i&lt;idx-1;i++)
              {
                  c[i] = c[i+1];
              }
              fscanf(fp,"%s",c[idx-1]);
          }
      }
      int i=0;
      while(i&lt;10)
      {
          cout&lt;&lt;c[i]&lt;&lt;"\n";
          i++;
      }
  }
  </code></pre>