Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!husc6!ut-sally!ut-ngp!dlnash From: dlnash@ut-ngp.UUCP Newsgroups: comp.lang.c Subject: Re: Help needed -> fseek() and ftell() in VMS VAX C Message-ID: <4685@ut-ngp.UUCP> Date: Thu, 12-Feb-87 12:25:26 EST Article-I.D.: ut-ngp.4685 Posted: Thu Feb 12 12:25:26 1987 Date-Received: Fri, 13-Feb-87 19:54:33 EST References: <384@umnd-cs-gw.umnd-cs.UUCP> Organization: UTexas Computation Center, Austin, Texas Lines: 55 Keywords: It doesn't do what the manual says .. In article <384@umnd-cs-gw.umnd-cs.UUCP>, jwabik@umnd-cs.UUCP (Jeff Wabik) writes: > I'm trying to fseek my way around a large (1.5MB) file using VAX VMS C, > and am having absolutely NO LUCK. > > Precise Problem Statement: > > 1) File is opened properly. > 2) I've converted LONG ftell variables from UNIX to INT > ftell variables for VMS. I've followed other instructions > in the manual as well. > 3) fseek(fp,n,0) does NOT bring me to byte n in the file.... > VAX C manual p. 16-21: "With record files, an fseek to a position that was not returned by ftell causes unpredictable behavior." I also tripped over this problem. If the file you are trying to fseek around in is not a Stream_LF file, then fseek will only seek to record boundaries, not character positions, or something broken like that. If you brought the data file over from another system, then it is probably not in Stream_LF format. The only way around this problem is to write a program which does something like: while ((c = fgetc(in)) != EOF) fputc(c, out); to make a copy of the file in Stream_LF format (which the stdio library creates by default). Then try fseeking around in the copy. It's a kludge, but it works. BTW, don't rely on feof, it is broken too. If you read the last byte from a file, so that the next read will return EOF, feof will not indicate the eof condition. If you try to read and get EOF, then try feof, it will indicate the eof condition. That in my mind is broken. It should indicate eof when there is nothing left to read, not after a read returns EOF. Oh, one more thing, make sure the variable 'c' in the above example is an int, not a char. The character 0xff is a perfectly valid character on a machine with an 8-bit character set, especially if your are reading and writing files with binary data in them. Fgetc will return 0x000000ff if the character it reads is 0xff. The constant EOF is 0xffffffff. The above loop will work correctly only if 'c' is an int, not a char. Don Nash UUCP: ...!{ihnp4, allegra, seismo!ut-sally}!ut-ngp!dlnash ARPA: dlnash@ngp.CC.UTEXAS.EDU BITNET: CCEU001@UTADNX, DLNASH@UTADNX UUU UUU U U The University of Texas at Austin U TTTTUTTTTTTTTT Computation Center U T U TT T U U TT "The world is basically non-linear." UUUUUUU TT TT TTTT