Path: utzoo!utgpu!attcan!uunet!husc6!rutgers!ucsd!ucbvax!CITHEX.CALTECH.EDU!carl From: carl@CITHEX.CALTECH.EDU (Carl J Lydick) Newsgroups: comp.os.vms Subject: Re: ftell & fseek Message-ID: <880801033703.110b@CitHex.Caltech.Edu> Date: 1 Aug 88 10:50:33 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 22 First, I'm sending this to INFO-VAX because my system never heard of the node AGR04.TO.CNR.IT. > I was working on adapting a C program, currently running under UNIX, to > VMS. I had some problems with the use of "ftell" and "fseek" . After a > call to "fseek" and a number 'n' of calls to "fgetc" are done, the next > "ftell" don't return the actual position ( n bytes after the last "fseek"), > but return the position of the last "fseek". I think that could be some > problems into the implementation of "fseek" and "getc" so that the pointer > to the position into the file is not correctly handled by this functions. In section 2.5.3 of the VAX-C Run-Time Library Reference Manual, ftell is documented as follows: The ftell function measures the offset from the beginning of the file. With record files, ftell returns the starting position of the current record, not the current byte offset. I think that the category "record files" doesn't include stream files. It should also be noted that, except for the first record of a file, ftell considers the current record to be the last record from which data was read; this means that if you read one record in its entirety, do an ftell then an fseek, you'll be back at the beginning of the record you just read. You can get around this by doing an ungetc(getc()) just before the call to ftell.