📄 main.c
字号:
// 提取大智慧二进制格式数据,将其转换为文本格式 skyofoct@yahoo.com.cn
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp,*fpout;
unsigned char buf[40] = {0};
unsigned char i,j,k;
unsigned long fhex = 0; //4 byte sum
unsigned long DecPrice = 0;
unsigned long Z_Price = 0;
unsigned long L_Price = 0;
char inFileName[80];
char outFileName[80];
if(argc != 3)
{
printf("\r\nUsage: bin2bin srcfile objfile");
return 1;
}
strcpy(inFileName, argv[1]);
strcpy(outFileName, argv[2]);
fp = fopen(inFileName, "rb");
if( fp == NULL)
{
printf("\r\nopen file %s failed!", inFileName);
return 1;
}
/*create object binary file*/
fpout = fopen(outFileName, "w+"); //creat new file,if the file exit,all data will be lost!
if(fpout == NULL)
{
printf("\r\ncreate file %s failed!", outFileName);
return 1;
}
while (fread(buf, 40, 1, fp))
{
fhex = 0;
DecPrice = 0;
i = 0;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24); //1 data
// printf("date: %8d\n",fhex);
fprintf(fpout,"%d", fhex);
fprintf(fpout," ");
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//2 open price
// printf("open price: %d\n",fhex);
if((fhex >= 0)&&(fhex < 1000))
{
L_Price = fhex % 1000;
fprintf(fpout,"0.%d", fhex);
fprintf(fpout," ");
}
else
{
Z_Price = fhex / 1000;
L_Price = fhex % 1000;
//printf("Z_Price: %d\n",Z_Price);
// printf("L_Price :%d\n",L_Price );
fprintf(fpout,"%d.%d",Z_Price,L_Price);
fprintf(fpout," ");
}
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//3 high price
// printf("high price: %d\n",fhex);
if((fhex >= 0)&&(fhex < 1000))
{
L_Price = fhex % 1000;
fprintf(fpout,"0.%d", fhex);
fprintf(fpout," ");
}
else
{
Z_Price = fhex / 1000;
L_Price = fhex % 1000;
fprintf(fpout,"%d.%d",Z_Price,L_Price);
fprintf(fpout," ");
}
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//4 low price
// printf("low price: %d\n",fhex);
if((fhex >= 0)&&(fhex < 1000))
{
L_Price = fhex % 1000;
fprintf(fpout,"0.%d", fhex);
fprintf(fpout," ");
}
else
{
Z_Price = fhex / 1000;
L_Price = fhex % 1000;
fprintf(fpout,"%d.%d",Z_Price,L_Price);
fprintf(fpout," ");
}
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//5 last price
// printf("last price: %d\n",fhex);
if((fhex >= 0)&&(fhex <1000))
{
L_Price = fhex % 1000;
fprintf(fpout,"0.%d",fhex);
fprintf(fpout," ");
}
else
{
Z_Price = fhex / 1000;
L_Price = fhex % 1000;
fprintf(fpout,"%d.%d",Z_Price,L_Price);
fprintf(fpout," ");
}
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//6 total exchange
// printf("total exchange: %d\n",fhex);
if((fhex >= 0)&&(fhex < 10))
{
L_Price = fhex % 10;
fprintf(fpout,"%d", fhex);
fprintf(fpout," ");
}
else
{
Z_Price = fhex / 10;
L_Price = fhex % 10;
fprintf(fpout,"%d.%d",Z_Price,L_Price);
fprintf(fpout," ");
}
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//7 total exch mon
// printf("total exch mon: %d\n",fhex);
fprintf(fpout,"%d", fhex);
fprintf(fpout," ");
i = i + 4;
fhex = buf[i] + ( buf[i + 1 ] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);//8 sample
// printf("sample: %d\n",fhex);
fprintf(fpout,"%d", fhex);
fprintf(fpout," ");
fprintf(fpout,"\n");
for (j = 0; j < 40; j++)
{
buf[j] = 0;
}
}
// fprintf(fpout,"");
// printf("Done!\n");
fclose(fp);
fclose(fpout);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -