title: C++ ftell Segmentation Fault
body: <p>I am trying to read data from a binary file. I have been given a struct with all of the variables to extract the data. I am using the fread function, and I need to get the total size of the file as one of freads inputs. I am using the ftell function to find the size, but I get a segmentation fault when I call the ftell function.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;stdio.h&gt;
  using namespace std;
  
  struct header{
    int so_on; 
    int so_forth;
    int etc;
  };
  
  int main(){
    FILE *fin;
    header cvvHeader;
    fin=fopen("file.binaryextension","r");
    int headersize= sizeof(header);
    header* ptr=&amp;cvvHeader;
    long filesize =ftell (fin); //Segmentation fault happens here
    fread(ptr,headersize,filesize,fin);
  }
  </code></pre>
  
  <p>Thanks for your help</p>