SHARE
TWEET

partial hcc file reader

a guest Jan 13th, 2015 220 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. #pragma pack(1)
  5. struct record {
  6.         int separator;
  7.         int time;
  8.         double open, high, low, close;
  9.         char additional[10];
  10. };
  11.  
  12. int main(void) {
  13.         FILE *fp;
  14.         struct record data;
  15.         int i, extra1, extra2;
  16.         time_t time;
  17.         struct tm *tm;
  18.         char timebuf[80];
  19.  
  20.         if ((fp=fopen("2015.hcc", "rb"))==NULL) {
  21.                 perror("2015.hcc"); exit(1);
  22.         }
  23.         // fseek(fp, 0x3be5, 0);
  24.         fseek(fp, 0xde1a, 0);
  25.         for (;;) {
  26.                 if (fread(&data, sizeof(int), 1, fp)==0)
  27.                         break;
  28.                 if ((data.separator & 0x00188884) != 0x00188884) {
  29.                         fprintf(stderr, "bad separator at %lx\n", ftell(fp));
  30.                         break;
  31.                 }
  32.                 extra1=data.separator>>28;
  33.                 extra2=((data.separator>>24)&0x0f)-1;
  34.                 fread(&data.time, sizeof(data)
  35.                                 -sizeof(data.separator)
  36.                                 -sizeof(data.additional)
  37.                                 +2 // 2 bytes seem always to be there
  38.                                 +extra1+extra2
  39.                         , 1, fp);
  40.                 time=data.time;
  41.                 tm=localtime(&time);
  42.                 strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S", tm);
  43.                 printf("%s %lf %lf %lf %lf ", timebuf, data.open,
  44.                         data.high, data.low, data.close);
  45.                 for (i=0; i<extra1+extra2+2; i++) {
  46.                         printf("%3d ", data.additional[i]&0xff);
  47.                 }
  48.                 putchar('\n');
  49.         }
  50.         fclose(fp);
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top