[Tutor] Moving file pointer

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jul 29 23:37:01 CEST 2004

> I'm trying to set the file pointer for a file on a posix machine.
> instance, I have a simple 5-byte file with data 'abcde'. I want to
> 'extend' the file to 10-bytes, but not initialize any data in those
> extra 5-bytes. They should be all zeros.

You can seek() the end of the file, then use write() to output
5 zeros. Or easier open the file in append mopde and just write
5 zero bytes.

To actually write ASCII code zero you can use escaping:

zero = '\000'
five-zeros = zero * 5

Alternatively you could open in binary mode and use the struct

As to initialising data, writing zeros is initialising it!


Alan G

More information about the Tutor mailing list