How to truncate filesize in C++



 DEVELOP > c-Plus-Plus > How to truncate filesize in C++

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "iceman"
Date: 21 Jan 2008 04:59:32 AM
Object: How to truncate filesize in C++
Hi all,
How do I truncate the file size.Is it possible to do this using
fopen ,fseek and fwrite.
Suppose I have a file of 30 KB if I want to reduce the size to
15KB,Howcan I do this without overwriting the the file[ie opening the
file for writing again and writing 15kb]
Itried this but it didnt work.
fseek(iofile,-150,SEEK_END);//150 is a random number
fwrite(numbers, sizeof(char),0,iofile);
Regards,
Jegan
.

User: "Phil Endecott"

Title: Re: How to truncate filesize in C++ 21 Jan 2008 06:33:14 AM
iceman wrote:

Hi all,
How do I truncate the file size.

I don't think that C++ provides a standard way to do this, but I could
be wrong.
On POSIX systems, you need the ftruncate() or truncate() call. The
former takes a file descriptor and the latter takes a filename. I'm not
sure about other systems; you should ask on a newsgroup specific to your
platform.
Phil.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER