Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!convex!mic!letni!utacfd!merch!cpe!hal6000!trsvax!don From: don@trsvax.UUCP Newsgroups: comp.lang.c Subject: Re: <4203@csusac.csus.edu> Message-ID: <50400006@trsvax> Date: 21 May 91 18:31:33 GMT References: <4203@csusac.csus.edu> Lines: 33 Nf-ID: #R:csusac.csus.edu:4203:trsvax:50400006:000:870 Nf-From: trsvax.UUCP!don May 6 14:19:00 1991 >Suppose I have a 100-byte file called "myfile.dat", and I want to get >rid of the last 10 bytes. The only way that I can figure out how to do >this is with something like the following: >main() >{ > char buf[100]; > FILE *fp; > fp = fopen("myfile.dat", "r"); > fread(buf, 1, 100, fp); > fclose(fp); > fp = fopen("myfile.dat", "w"); > fwrite(buf, 1, 90, fp); > fclose(fp); >} This does not necessarily truncate files in all operating systems. To correctly truncate the file using ANSI calls, add the line remove("myfile.dat"); after the first call to fclose(). --------------------------------------------------------------------------- I wouldn't bring up Paris if I were you. It's poor salesmanship. -- Casablanca Don Subt The opinions expressed above are Tandy Corp. strictly mine, not my employer's. 817-390-2923 don%trsvax@rwsys.lonestar.org