FILE * fp = fopen( "C:\\dzh\\DATA\\SHase\\Min\\000001.nmn", "rb" );
if( ! fp ) return 0;
char pcBuf[ 40 ] = "" ;
int i = 0;
while(i<48)
{
i++;
fread( pcBuf, sizeof( pcBuf ), 1, fp );
unsigned uTime = *(unsigned * ) pcBuf;
unsigned uYear = ( uTime>>20 );//右移20位
unsigned uMonth = ( ( uTime<<12)>>28);//先左移12位再右移28位
unsigned uDate = ( ( uTime<<16)>>27);
unsigned uHour = ( ( uTime<<21)>>27);
unsigned uMinute = ( ( uTime<<26)>>26);
double dOpen = (double)( *(float *)(pcBuf + 4) ) / 1000.0;
double dHigh = (double)( *(float * )(pcBuf + 8) )/ 1000.0;
double dLow = (double)(*(float*)(pcBuf+12))/1000.0;
double dClose = (double)(*(float*)(pcBuf+16) )/1000.0;
double dAmount = (double)(*(float*)(pcBuf+20));
double dVolume = (double)(*(float*)(pcBuf+24)); printf( "%u-%02u-%02u %02u:%02u %9.2f,%9.2f,%9.2f%9.2f%11.2f%11.2f\n",
uYear, uMonth, uDate, uHour, uMinute, dOpen, dHigh, dLow, dClose, dAmount, dVolume );
}
printf("%d",sizeof(unsigned));
fclose( fp );
system("PAUSE");
return 0;
有人帮我改下吗?
谢谢了
if( ! fp ) return 0;
char pcBuf[ 40 ] = "" ;
int i = 0;
while(i<48)
{
i++;
fread( pcBuf, sizeof( pcBuf ), 1, fp );
unsigned uTime = *(unsigned * ) pcBuf;
unsigned uYear = ( uTime>>20 );//右移20位
unsigned uMonth = ( ( uTime<<12)>>28);//先左移12位再右移28位
unsigned uDate = ( ( uTime<<16)>>27);
unsigned uHour = ( ( uTime<<21)>>27);
unsigned uMinute = ( ( uTime<<26)>>26);
double dOpen = (double)( *(float *)(pcBuf + 4) ) / 1000.0;
double dHigh = (double)( *(float * )(pcBuf + 8) )/ 1000.0;
double dLow = (double)(*(float*)(pcBuf+12))/1000.0;
double dClose = (double)(*(float*)(pcBuf+16) )/1000.0;
double dAmount = (double)(*(float*)(pcBuf+20));
double dVolume = (double)(*(float*)(pcBuf+24)); printf( "%u-%02u-%02u %02u:%02u %9.2f,%9.2f,%9.2f%9.2f%11.2f%11.2f\n",
uYear, uMonth, uDate, uHour, uMinute, dOpen, dHigh, dLow, dClose, dAmount, dVolume );
}
printf("%d",sizeof(unsigned));
fclose( fp );
system("PAUSE");
return 0;
有人帮我改下吗?
谢谢了
{
uint a = 2;
Console.WriteLine("{0:00}", a);
Console.ReadKey();
try
{
FileStream fs = File.OpenRead("C:\\dzh\\DATA\\SHase\\Min\\000001.nmn");
byte[] pcBuf = new byte[40];
int i = 0;
while (i < 48)
{
i++;
fs.Read(pcBuf, 0, 40);
uint uTime = 0;
BitConverter.ToUInt32(pcBuf, 0);
uint uYear = (uTime >> 20);//右移20位
uint uMonth = ((uTime << 12) >> 28);//先左移12位再右移28位
uint uDate = ((uTime << 16) >> 27);
uint uHour = ((uTime << 21) >> 27);
uint uMinute = ((uTime << 26) >> 26);
double dOpen = BitConverter.ToSingle(pcBuf, 4) / 1000.0;
double dHigh = BitConverter.ToSingle(pcBuf, 8) / 1000.0;
double dLow = BitConverter.ToSingle(pcBuf, 12) / 1000.0;
double dClose = BitConverter.ToSingle(pcBuf, 16) / 1000.0;
double dAmount = BitConverter.ToSingle(pcBuf, 20);
double dVolume = BitConverter.ToSingle(pcBuf, 24); Console.WriteLine("{0}-{1:00}-{2:00} {3:00}:{4:00} {5:#########.00},{6:#########.00},{7:#########.00}{8:#########.00}{9:###########.00}{10:###########.00}\n",
uYear, uMonth, uDate, uHour, uMinute, dOpen, dHigh, dLow, dClose, dAmount, dVolume);
}
fs.Close();
Console.ReadKey();
}
catch
{
return;
}
Console.ReadKey();
}
{
try
{
FileStream fs = File.OpenRead("C:\\dzh\\DATA\\SHase\\Min\\000001.nmn");
byte[] pcBuf = new byte[40];
int i = 0;
while (i < 48)
{
i++;
fs.Read(pcBuf, 0, 40);
uint uTime = 0;
BitConverter.ToUInt32(pcBuf, 0);
uint uYear = (uTime >> 20);//右移20位
uint uMonth = ((uTime << 12) >> 28);//先左移12位再右移28位
uint uDate = ((uTime << 16) >> 27);
uint uHour = ((uTime << 21) >> 27);
uint uMinute = ((uTime << 26) >> 26);
double dOpen = BitConverter.ToSingle(pcBuf, 4) / 1000.0;
double dHigh = BitConverter.ToSingle(pcBuf, 8) / 1000.0;
double dLow = BitConverter.ToSingle(pcBuf, 12) / 1000.0;
double dClose = BitConverter.ToSingle(pcBuf, 16) / 1000.0;
double dAmount = BitConverter.ToSingle(pcBuf, 20);
double dVolume = BitConverter.ToSingle(pcBuf, 24); Console.WriteLine("{0}-{1:00}-{2:00} {3:00}:{4:00} {5:#########.00},{6:#########.00},{7:#########.00}{8:#########.00}{9:###########.00}{10:###########.00}\n",
uYear, uMonth, uDate, uHour, uMinute, dOpen, dHigh, dLow, dClose, dAmount, dVolume);
}
fs.Close();
Console.ReadKey();
}
catch
{
return;
}
Console.ReadKey();
}
BitConverter.ToUInt32(pcBuf, 0);修改为uint uTime = BitConverter.ToUInt32(pcBuf, 0);效果和你的一样。你发来的文件估计是错的。扩展名都不一样。和你c的读取效果一致。