title: Go to a certain point of a binary file in C (using fseek) and then reading from that location (using fread)
body: <p>I am wondering if this is the best way to go about solving my problem. </p>
  
  <p>I know the values for particular offsets of a binary file where the information I want is held...What I want to do is jump to the offsets and then read a certain amount of bytes, starting from that location.</p>
  
  <p>After using google, I have come to the conclusion that my best bet is to use fseek() to move to the position of the offset, and then to use fread() to read an amount of bytes from that position.</p>
  
  <p>Am I correct in thinking this? And if so, how is best to go about doing so? i.e. how to incorporate the two together.</p>
  
  <p>If I am not correct, what would you suggest I do instead?</p>
  
  <p>Many thanks in advance for your help.</p>
  
  <p>Matt</p>
  
  <p><em>Edit</em>:</p>
  
  <p>I followed a tutorial on fread() and adjusted it to the following:</p>
  
  <pre><code>    `#include &lt;stdio.h&gt;
      int main()
      {
        FILE *f;
        char buffer[11];
        if (f = fopen("comm_array2.img", "rt"))
        {
          fread(buffer, 1, 10, f);
          buffer[10] = 0;
          fclose(f);
          printf("first 10 characters of the file:\n%s\n", buffer);
        }
        return 0;
      }`
  </code></pre>
  
  <p>So I used the file 'comm_array2.img' and read the first 10 characters from the file.</p>
  
  <p>But from what I understand of it, this goes from start-of-file, I want to go from some-place-in-file (offset)</p>
  
  <p>Is this making more sense?</p>
  
  <p>Edit Number 2:</p>
  
  <p>It appears that I was being a bit dim, and all that is needed (it would seem from my attempt) is to put the fseek() before the fread() that I have in the code above, and it seeks to that location and then reads from there.</p>