title: Read binary file with C++ and translate some contents in it
body: <p>I am trying to learn more about binary files, so I started with HexEdit, and I manually wrote a file and created a template for it. Here is my work:</p>
  
  <p><img src="https://i.stack.imgur.com/9Ul9U.png" alt="enter image description here"></p>
  
  <p>Now, I started working on a console application in C++ Win32 to read the contents in that file and make them look friendly. Here is part my code:</p>
  
  <pre><code>typedef unsigned char BYTE;
  
  long getFileSize(FILE *file)
  {
      long lCurPos, lEndPos;
      lCurPos = ftell(file);
      fseek(file, 0, 2);
      lEndPos = ftell(file);
      fseek(file, lCurPos, 0);
      return lEndPos;
  }
  
  int main()
  {
      const char *filePath = "D:\\Applications\\ColorTableApplication\\file.clt";
      BYTE *fileBuf;          // Pointer to our buffered data
      FILE *file = NULL;      // File pointer
  
      if ((file = fopen(filePath, "rb")) == NULL)
          printf_s("Could not open specified file\n");
      else {
          printf_s("File opened successfully\n");
          printf_s("Path: %s\n", filePath);
          printf_s("Size: %d bytes\n\n", getFileSize(file));
      }
  
      long fileSize = getFileSize(file);
  
      fileBuf = new BYTE[fileSize];
  
      fread(fileBuf, fileSize, 1, file);
  
      for (int i = 0; i &lt; 100; i++){
          printf("%X ", fileBuf[i]);
      }
  
      _getch();
      delete[]fileBuf;
          fclose(file);   // Almost forgot this 
      return 0;
  }
  </code></pre>
  
  <p>(I provided that much code because I want to be clear, to help you get the idea about what I am trying to do)</p>
  
  <p>First of all, I need to get the first 14 bytes and write them in the console as text, and then, in a <code>for</code> I need to write something like this for each color:</p>
  
  <pre><code>black      col_id = 1; R = 00; G = 00; B = 00;
  red        col_id = 2; R = FF; G = 00; B = 00;
  etc...
  </code></pre>
  
  <p>How can I read and translate these bytes?</p>