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


Тест 3 - часть 2


{ int sz;
void *p;
long p0;
fseek(fd,0L,SEEK_SET);
fread(&#38sz,sizeof(int),1,fd);
fread(&#38p0,sizeof(long),1,fd);
p = malloc(sz);
fseek (fd, p0 + sizeof(long)*n, SEEK_SET);
fread (&#38p0, sizeof(long),1,fd);
fseek(fd, p0, SEEK_SET);
fread(p, sz, 1, fd);
return(p);
}
// 8------------------------------------------------------


char *F(int n, FILE *fd)
{ char *p;
long fp;
int i;
fseek(fd, sizeof(long)*n,SEEK_SET);
fread(&#38fp,sizeof(long),1,fd);
fseek(fd,fp,SEEK_SET);
n = 80; p = malloc(n);
for (i=0;; i++)
{
if (i==n) p = realloc(p, n=n*2);
fread(p+i,1,1,fd);
if (p[i]=='\0') return(p);
}
return(p);
}
// 9------------------------------------------------------


&#35define FNULL -1L
char *F(int n, FILE *fd)
{ long p0;
int sz;
char *p;
fseek(fd,0L,SEEK_SET);
fread(&#38p0,sizeof(long),1,fd);
for (; p0!=FNULL &#38&#38 n!=0; n--)
{
fseek(fd,p0,SEEK_SET);
fread(&#38p0,sizeof(long),1,fd);
}
if (p0==FNULL) return(NULL);
fread(&#38sz,sizeof(int),1,fd);
p = malloc(sz+1);
fread(p,sz,1,fd);
p[sz]='\0';
return(p);
}
// 10--------------------------------------------------------


char *F(FILE *fd)
{ int n;
char *p;
fread(&#38n,sizeof(int),1,fd);
if (n==0) return(NULL);
p = malloc(n);
fread(p,n,1,fd);
return p;
}
// 11--------------------------------------------------------


void F(FILE *fd, char *s)
{ int n;
char *p;
fseek(fd,0L,SEEK_END);
n = strlen(s)+1;
fwrite(&#38n,sizeof(int),1,fd);
fwrite(p,n,1,fd);
}
// 12--------------------------------------------------------


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


void F(FILE *fd, double *s, int dn)
{ int n;
n = dn * sizeof(double);
fseek(fd,0L,SEEK_END);
fwrite(&#38n,sizeof(int),1,fd);
fwrite(s,sizeof(double),dn,fd);
}
// 14------------------------------------------------------




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



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