Hi all,

I am trying to read time from a binary file, but I couldn't get the right value. Each record is 112 bytes in binary file.

time format is YYYYDDDHHMMSSTHT
YYYY = Year
DDD = Day of the year
HH = hour
MM = minute
SS = second
T = tenth of the second
H = Hundread of the second
T = Thousand of the second.

Here is my program

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>



int main (int argc, char *argv[])
{
FILE *faatr;
FILE *outfile;
struct
{
char emapty[4];
unsigned long id;
char emapty1[12];
char time[8];
char empty2[74];
unsigned short key;
char empty3[8];
} mytype;



if (argc < 2)
{

printf ("Usage: %s key number\n", argv[0]);
exit (0);

}

faatr = fopen("myfile", "rb");
outfile = fopen("out.txt", "wb");


if (!faatr)
{
printf ("File can not be opened for reading\n"); 
}
else
{
printf ("File opened.\n"); 
printf("argument = %d\n",atoi(argv[1]));
while(!feof(faatr))
{

fread(&mytype,sizeof(mytype),1,faatr);
if(!feof(faatr))
{ 
/*printf("1st value = %d\n",mytype.key);*/
/* fprintf(outfile,"key valude= %u\n",mytype.key);*/
if(mytype.key==atoi(argv[1]))
{
printf ("Key is found\n"); 
fprintf(outfile,"freq = %u\n",mytype.id);
fprintf(outfile,"start_time= %s\n",mytype.time);
}

}
}
}
fclose(faatr); 
fclose(outfile);
return(0);
}

Here is binary file ( 112 bytes of each record) Seems like it is binary decimal file.

I used od -x myfile to look at it.
For the first record, time field starts 21 to 28 (1996 0301 9112 8831) and it seems like in YYYYDDDHHMMSSTHT format.
How can I get this value?

0000000 0001 f000 002f 7470 2020 2020 2020 2020
0000020 2020 2020 1996 0301 9112 8831 1995 2681
0000040 7575 3332 1995 2681 7580 8349 0000 0000
0000060 2020 2020 2020 2020 5452 4149 4e30 3035
0000100 0000 05dc 3033 3031 3931 3032 2020 2020
0000120 2002 0001 0000 0000 0000 e040 01ff 0001
0000140 0800 0000 0000 0018 0002 0000 0000 0000
0000160 0000 a000 002f 7470 2020 2020 2020 2020
0000200 2020 2020 1996 0301 9113 0348 1995 2681
0000220 7581 2850 1995 2681 7581 7349 0000 0000
0000240 2020 2020 2020 2020 5452 4149 4e30 3035
0000260 0000 05dc 3033 3031 3931 3032 2020 2020
0000300 2002 0002 0000 0000 0000 e040 02ff 0001
0000320 0800 0000 0000 0001 0003 0000 0000 0000
0000340 0004 7000 002f 7470 2020 2020 2020 2020
0000360 2020 2020 1996 0301 9113 1565 1995 2681
0000400 7584 8183 1995 2681 7592 3219 0000 0000
0000420 2020 2020 2020 2020 5452 4149 4e30 3035
0000440 0000 05dc 3033 3031 3931 3032 2020 2020
0000460 2002 0003 0000 0000 0000 e040 02ff 0001
0000500 0800 0000 0000 0002 0004 0000 0000 0000


I will be really appreciate your help.

Thanks.