How do you truncate a file?

Brian Fitzgerald fitz at mml0.meche.rpi.edu
Mon May 6 03:35:30 AEST 1991


Rudi Cilibrasi writes:
>Suppose I have a 100-byte file called "myfile.dat", and I want to get
>rid of the last 10 bytes.

#include <stdio.h>
main () {
int	i;
for (i=0; i < 90 ; i++) {
		(void) putchar(getchar());
	}
}

It has worked for me in the past.

Use the program with shell i/o redirection, as in

program < myfile.dat > truncated.dat

Brian



More information about the Comp.lang.c mailing list