title: lseek() and read() proper usage
body: <p>I am reading in a "non human readable file" full of structs. I have declared my struct that is a known member of the file.  I want to read the file from the begging to the sizeof the stuct populating the fields.  I don't understand why my out put is zero for all the struct fields. I have looked at the man pages of these functions and I believe I am using them correctly, so am I just not accessing the fields correctly from the buffer, or? please see below code snippet.</p>
  
  <pre><code>int main (int argc, char * argv[])
  {
      // make sure you were given an image
      if (argc != 2)
      {
          printf("no image\n");
          return -1;
      }
  
      int fs_fd = open(argv[1], O_RDWR);
  
      // make sure you can open the image
      if(fs_fd == -1)
      {
          printf("image is busted\n");
          return -1;
      }
  
      struct superblock *mySB;
      mySB = malloc(sizeof(struct superblock));
      mySB-&gt;size = 0;
      mySB-&gt;nblocks = 0;
      mySB-&gt;ninodes = 0;
  
      char buffer[4096];
      if(lseek(fs_fd, 0, SEEK_SET));
      read(fs_fd, &amp;buffer, sizeof(struct superblock));
  
      mySB-&gt;size = buffer[0];
      mySB-&gt;nblocks = buffer[4];
      mySB-&gt;ninodes = buffer[8];
  
      printf("Size: %u, nblocks: %u, ninodes: %u\n", mySB-&gt;size, mySB-&gt;nblocks, mySB-&gt;ninodes);
  }
  </code></pre>
  
  <p>ok, suggestions taken into consideration, though in truth I'm not concerned withe good error checking at this point.  the following results in a seg fault as i'm sure this is not reading into the struct correctly, but I am trying to use the suggestions.</p>
  
  <pre><code>int main (int argc, char * argv[])
  {
      // make sure you were given an image
      if (argc != 2)
      {
           printf("usage: file.img");
           return -1;
      }
  
      int fd = open(argv[1], O_RDWR);
  
      // make sure you can open the image
      if(fd == -1)
      {
          perror("Error&gt; ");
          return -1;
      }
  
      struct superblock *mySB;
      mySB = malloc(sizeof(struct superblock));
      read(fd, &amp;mySB, sizeof(struct superblock));
  
  
      printf("Size: %u, nblocks: %u, ninodes: %u\n", mySB-&gt;size, mySB-&gt;nblocks, mySB-&gt;ninodes);
  } 
  </code></pre>