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


Вопросы без ответов - часть 2


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 = new char [n];
for (i=0;; i++)
{
if (i==n) p = (char*)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 = new char[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 = new char[n];
fread(p,n,1,fd);
return p;
}
//-------------------------------------------------------- 11


void F(FILE *fd, char *s)
{ int n;
fseek(fd,0L,SEEK_END);
n = strlen(s)+1;
fwrite(&#38n,sizeof(int),1,fd);
fwrite(s,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 = new double[ dn+1];
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


void F(FILE *fd)
{ int n;
void *p;
fread(&#38n,sizeof(int),1,fd);
if (n==0) return;
p = ( void*) new char[n];
fread(p,n,1,fd);
switch (n)
{
case sizeof(int): cout &#60&#60 *(int*)p; break;
case sizeof(long): cout &#60&#60 *(long*)p; break;



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



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