Код: Выделить всё
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
typedef struct TypeBuf
{
unsigned char Type[1];
unsigned char Dlit[2];
unsigned char NumberA[4];
unsigned char NumberB[12];
unsigned char DateTime[8];
};
char buf[27];
struct TypeBuf *Var1;
FILE *input;
FILE *output;
WriteBuf()
{
int ret;
int i=0;
unsigned char ch;
while (i < 27)
{
ret=fread(&ch,sizeof(char),1,input);
if (ret==0) return(1);
buf[i]=ch;
i++;
}
return(0);
}
WriteFile()
{
int i;
Var1 = (struct TypeBuf *) buf;
<пропущено для экономии места>
fprintf(output, ";");
// DATE+TIME
unsigned char temp;
temp = Var1->DateTime[7]; // переставляем местами байтики ибо Солярис
Var1->DateTime[7] = Var1->DateTime[0];
Var1->DateTime[0] = temp;
temp = Var1->DateTime[6];
Var1->DateTime[6] = Var1->DateTime[1];
Var1->DateTime[1] = temp;
temp = Var1->DateTime[5];
Var1->DateTime[5] = Var1->DateTime[2];
Var1->DateTime[2] = temp;
temp = Var1->DateTime[4];
Var1->DateTime[4] = Var1->DateTime[3];
Var1->DateTime[3] = temp;
double *DateTime;
DateTime = (double *)Var1->DateTime;
*DateTime = *DateTime - 25569; // вот тут эта падла сегфолтится.....
*DateTime = *DateTime * 86400;
time_t t = *DateTime;
struct tm* lt = gmtime(&t);
char time_str[20];
sprintf(time_str, "%04d%02d%02d %02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
fprintf(output,"%s", time_str);
fprintf(output,";");
Не пойму что я делаю не так?????
Код: Выделить всё
]$gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.2