Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. // ConsoleApplication5.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <iterator>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. struct cell
  13. {
  14.     unsigned char operationCode;
  15.     unsigned char operationParameter;
  16.     unsigned int legnthToOperateOn;
  17. } typedef cell;
  18.  
  19. int _tmain(int argc, _TCHAR* argv[])
  20. {
  21.     ifstream myfile;
  22.     cell cur;
  23.     cell* cells;
  24.     int i;
  25.     int length;
  26.     char* buffer;
  27.     myfile.open("Key.bin", ios::binary);
  28.     buffer = new char[4];
  29.     myfile.seekg(0, myfile.end);
  30.     length = myfile.tellg();
  31.     myfile.seekg(0, myfile.beg);
  32.     cells = new cell[length/6];
  33.     // read data as a block:
  34.     for (i = 0; i < length / 6; i++)
  35.     {
  36.         myfile.read(buffer, 1);
  37.         cur.operationCode = buffer[0];
  38.         myfile.read(buffer, 1);
  39.         cur.operationParameter = buffer[0];
  40.         myfile.read(buffer, 4);
  41.         cur.legnthToOperateOn = (buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | (buffer[0]);
  42.         cells[i] = cur;
  43.         cout << "\ncells[" << i << "]\noperationCode: " << (int)cur.operationCode << "\noperationParametere: " << (int)cur.operationParameter << "\nlengthToOperateOn: " << cur.legnthToOperateOn << endl;
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement