Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!uflorida!ziggy!screamer!stelmack From: stelmack@screamer.csee.usf.edu (Gregory M. Stelmack) Newsgroups: comp.lang.c Subject: C file access question Summary: Having trouble adding to end of file Message-ID: <28@screamer.csee.usf.edu> Date: 13 Sep 90 17:39:59 GMT Followup-To: comp.lang.c Distribution: comp.lang.c Organization: University of South Florida, Department of Computer Science and Engineering Lines: 37 I've got some code I'm writing for ANSI file access, and have run into a problem that nobody here can help me with (I've asked). What I am trying to do is implement a free space list in a file that, when adding a record, the code will look for an appropriate free space record. If it finds one, it sticks the data there. If it doesn't, I want to add it on to the end of the file. I got this to work on my Amiga using Lattice C 5.04. But, when I uploaded it to my school's SUN computers, it doesn't run. (SUNOS 4.0.3, cc compiler). But, it compiles fine. Anyway, here's the skeleton code (I will send complete code to anyone who wishes to look further): int error=0; long DataLen; /* passed to function, value checked */ FILE *db; ... db = fopen("dd.data","rb+"); /* db is checked to make sure file opened */ ... error = fseek(db,0L,2); /* seek end of file */ if (error==-1) return(GS_DATA_SEEK_ERROR); error = fwrite((char *)&DataLen,sizeof(DataLen),1,db); if (error!=1) return(GS_DATA_WRITE_ERROR); <-- error = 0, so it returns ... I have tried the seek both ways (EOF back, start forward), and checked all parameters, and everything looks OK. I have called perror() before returning, and it gives an Error 0 (no error). Nothing is written to the file. Any ideas from anyone who is familiar with the ANSI level 2 file functions? Thanks in advance, -- Greg Stelmack -- Email: stelmack@sol.csee.usf.edu -- USmail: USF Box 1510, Tampa, FL 33620-1510 -- Amiga: the only way to compute!