How to truncate a file? 
Author Message
 How to truncate a file?

Please, I'm needing a help.

I have a file with 100.000bytes I need to use only the 50.000 initial
bytes only.

How can I do that without to write a program to copy (byte by byte)
the file with the first 50.000 bytes.

Don't have an easyer way like to put an EOF char at the 50.001 byte of
the file???

How to work with the FAT in this case?

Thank you....

Roberto Lopes



Tue, 25 Jan 2000 03:00:00 GMT  
 How to truncate a file?

Quote:

> I have a file with 100.000bytes I need to use only the 50.000 initial
> bytes only.

> How can I do that without to write a program to copy (byte by byte)
> the file with the first 50.000 bytes.

> Don't have an easyer way like to put an EOF char at the 50.001 byte of
> the file???

If you are trying to truncate (shorten) the file, use the chsize
function... not standard, but widely available.

        -- AK

--



Tue, 25 Jan 2000 03:00:00 GMT  
 How to truncate a file?



Quote:

>> I have a file with 100.000bytes I need to use only the 50.000 initial
>> bytes only.

>> How can I do that without to write a program to copy (byte by byte)
>> the file with the first 50.000 bytes.

You can do it a group of bytes at a time using fread() and fwrite().

Quote:
>> Don't have an easyer way like to put an EOF char at the 50.001 byte of
>> the file???

EOF isn't a character, it is an error indication returned by some input
functions to indicate that they failed to return any data.

If you are trying to truncate (shorten) the file, use the chsize

Quote:
>function... not standard, but widely available.

Except on the many platforms where it isn't! :-)

--
-----------------------------------------


-----------------------------------------



Tue, 25 Jan 2000 03:00:00 GMT  
 How to truncate a file?

Quote:

>Please, I'm needing a help.

>I have a file with 100.000bytes I need to use only the 50.000 initial
>bytes only.

>How can I do that without to write a program to copy (byte by byte)
>the file with the first 50.000 bytes.

>Don't have an easyer way like to put an EOF char at the 50.001 byte of
>the file???

Hi Roberto, here is an answer in the FAQ:

19.13:  How can a file be shortened in-place without completely clearing
        or rewriting it?

A:      BSD systems provide ftruncate(), several others supply chsize(),
        and a few may provide a (possibly undocumented) fcntl option
        F_FREESP.  Under MS-DOS, you can sometimes use write(fd, "", 0).
        However, there is no portable solution, nor a way to delete
        blocks at the beginning.  See also question 19.14.

Quote:
>How to work with the FAT in this case?

You might want to check comp.os.msdos.programmer, C doesn't
know about FATs.
--
Scott Allen            



Fri, 28 Jan 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How can I truncate the file ?

2. how to truncate a file?

3. How do you truncate a file?

4. how to truncate a file opened in text mode

5. Function to truncate a file?

6. How truncate a file from a specific position?

7. How to truncate a file?

8. how to truncate a file

9. Help ! How do I truncate a file with stdio ?

10. Use C/C++ to truncate a file? How?

11. How do I Truncate a file in C or C++ ???

12. Truncating a file.

 

 
Powered by phpBB® Forum Software