Problem with fseek; fails at erratic intervals

Jon Grantham grantham at math.lsa.umich.edu
Sat Jul 7 02:22:08 AEST 1990


[SunOS 4.0.3 on a Sun 4/390]
I have a bug in a program that's driving me batty...apologizes if it's simple,
but I've RTFM & asked people for help to no avail.

I have a program findgn that accepts an int argument and parses output from
another program to give values of a function, g(n).  It gives the values for
n equal to the argument through the argument +510.  For some reason,
findgn 1000 messes up g(1033) [This corresponds to n=1000, l=33 below], but
findgn 1033 calculates it fine.  [This corresponds to n=1033, l=0]
(Both mess up in other places, but I'm using 1033 for debugging.)
I've narrowed the problem down to fseek(gn.25,100,0) returning -1 for
findgn 1000, but not findgn 1033.  I have no idea why it should differ.

Portions of the code are included below, the rest doesn't matter (I think)
and is deleted to save bandwidth.  If you really want to know, send e-mail.

#include <stdio.h>
...
#define ATONCE 510

...
  for (i=0; i <= ATONCE; ++i)
	j[i]=n+i;
  for (i=1; i <= pin; ++i)
  {
    sprintf(filename,"gn.%d",i);
    fi=fopen(filename,"r");
...
    for (l=0; l <= ATONCE; ++l)
      {
        k=j[l]-1;
        fs=fseek(fi,k,0);                     /* Here's the problem */
        repo=powers[i][l]=getc(fi);
...
      }
    fclose(fi);
  }
--
grantham at math.lsa.umich.edu   Jon_Grantham at ub.cc.umich.edu   grantham at super.org



More information about the Comp.lang.c mailing list