Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!ucdavis!csusac!usenet From: cilibrar@athena.ecs.csus.edu (Rudi Cilibrasi) Newsgroups: comp.lang.c Subject: How do you truncate a file? Keywords: fwrite, file, truncate, fread Message-ID: <1991May5.024348.4203@csusac.csus.edu> Date: 5 May 91 02:43:48 GMT Sender: usenet@csusac.csus.edu (News account (alt)) Distribution: usa Organization: California State University, Sacramento Lines: 19 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 seems to be a rather roundabout way to accomplish a simple task. Is there any way to accomplish the same thing without reading the entire file into memory? Thanks for any help.