Incompatible data type fpos_t in C

This is from a program I wrote over in 1998 that I am trying to compile on a linux machine:

void write_line (FILE *fp, int rec_no, line_rec *arec)
{
   fpos_t woffset;
   woffset = (rec_no - 1) * sizeof(line_rec);
   fsetpos(fp,&woffset);
   fwrite(arec,sizeof(line_rec),1,fp);
}

On the line starting with "woffset =" I get

reclay.c:436: error: incompatible types in assignment

What do I need to do to get woffset to calculate?
TIA

From man fsetpos:

       The fgetpos() and fsetpos() functions are alternate interfaces  equiva�
       lent  to ftell() and fseek() (with whence set to SEEK_SET), setting and
       storing the current value of the file offset into or  from  the  object
       referenced by pos.  On some non-UNIX systems, an fpos_t object may be a
       complex object and these routines may be the only way to portably repo�
       sition a text stream.

So you are playing with fire by assuming that fpos_t is an integer.

I recommend fseek instead:

void write_line(FILE *fp, int rec_no, line_rec *arec)
{
        long woffset = (rec_no - 1) * sizeof(line_rec);
        fseek(fp, woffset, SEEK_SET);
        fwrite(arec, sizeof(line_rec), 1, fp);
}
2 Likes

Thank you!! It's been years since I did anything in C.