<4203 at csusac.csus.edu>
don at trsvax.UUCP
don at trsvax.UUCP
Wed May 22 04:31:33 AEST 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 at rwsys.lonestar.org
More information about the Comp.lang.c
mailing list