Информатика и технология программирования


Вопросы без ответов


Определить структуру данных в двоичном файле произвольного доступа


//------------------------------------------------------bk59-13.cpp


struct man { int dd,mm,yy; };
man *F(int n, FILE *fd)
{ man *p;
p = new man;
fseek (fd, (long)sizeof( man)*n, SEEK_SET);
fread (p, sizeof( man),1,fd);
return(p);
}
//------------------------------------------------------ 2


void *F(FILE *fd)
{ int n;
void *p;
fread(&#38n,sizeof(int),1,fd);
if (n==0) return(NULL);
p = ( void*) new char[n];
fread(p,n,1,fd);
return(p);
}
//------------------------------------------------------ 3


double *F(FILE *fd)
{ int n;
double *p;
fread(&#38n,sizeof(int),1,fd);
if (n==0) return(NULL);
p = new double[ n+1];
fread(p,sizeof(double),n,fd);
p[n]=0.0;
return(p);
}
//------------------------------------------------------ 4


&#35define FNULL -1L
struct xxx { long fnext; . . . };
xxx *F(int n,FILE *fd)
{ xxx *p;
long p0;
p = new xxx;
fseek(fd,0L,SEEK_SET);
fread(&#38p0,sizeof(long),1,fd);
for (; p0!=FNULL &#38&#38 n!=0; n--, p0 = p-&#62fnext)
{
fseek(fd,p0,SEEK_SET);
fread(p,sizeof( xxx),1,fd);
}
return(p);
}
//------------------------------------------------------ 5


struct man { int dd,mm,yy; };
man *F(int n, FILE *fd)
{ man *p;
long fp;
p = new man;
fseek(fd, sizeof(long)*n,SEEK_SET);
fread(&#38fp,sizeof(long),1,fd);
fseek(fd,fp,SEEK_SET);
fread(p,sizeof( man),1,fd);
return(p);
}
//------------------------------------------------------ 6


void *F(int n, FILE *fd)
{ int sz;
void *p;
fseek(fd,0L,SEEK_SET);
fread(&#38sz,sizeof(int),1,fd);
p = ( void*) new char[sz];
fseek (fd, (long)sz * n +sizeof(int), SEEK_SET);
fread (p, sz,1,fd);
return(p);
}
//------------------------------------------------------ 7


void *F(int n, FILE *fd)
{ int sz;
void *p;
long p0;
fseek(fd,0L,SEEK_SET);
fread(&#38sz,sizeof(int),1,fd);
fread(&#38p0,sizeof(long),1,fd);
p = (void*)new char[sz];
fseek (fd, p0 + sizeof(long)*n, SEEK_SET);
fread (&#38p0, sizeof(long),1,fd);
fseek(fd, p0, SEEK_SET);



Начало  Назад  Вперед



Книжный магазин