Insert EOF marker into file

Discussion in 'C Programming' started by zambak, Nov 16, 2003.

  1. zambak

    zambak Guest

    Hi

    I have decompression function which opens compressed input file,
    grabs the header containing the original file size and the date compressed
    and
    starts decompressing data into output file....
    Because of the padding, decompessed file may be larger than original by up
    to 7 bytes....


    What I want to do is to insert EOF at the position == original file size
    into output file...
    So after processing I want to do

    // set the position in output file to original file size
    fseek(out_file, orig_size, SEEK_SET);
    // write EOF in that position
    // ???????????????????????????????? fwrite maybe???
    // close output file
    fclose(out_file);


    Question is how do I "inject" EOF at the position i want....What is the code
    for it???

    Thanks
    zambak
     
    zambak, Nov 16, 2003
    #1
    1. Advertising

  2. zambak wrote:
    > Hi
    >
    > I have decompression function which opens compressed input file,
    > grabs the header containing the original file size and the date compressed
    > and
    > starts decompressing data into output file....
    > Because of the padding, decompessed file may be larger than original by up
    > to 7 bytes....
    >
    >
    > What I want to do is to insert EOF at the position == original file size
    > into output file...
    > So after processing I want to do


    Some systems may have ftruncate(), but it is not standard C.

    Best bet is to not write more than the length of file that you want.

    -- glen
     
    glen herrmannsfeldt, Nov 16, 2003
    #2
    1. Advertising

  3. zambak

    Derk Gwen Guest

    # Question is how do I "inject" EOF at the position i want....What is the code
    # for it???

    There is no C standard for reducing the size of an existing file. If you
    create a new file, the operating system of any quality will not allocate
    much more space than the highest offset you write.

    Why are you decompressing into a file? You're going to destroy whatever
    is in the file from where you start writing. You can accomplish the same
    in standard C by openning what was the output as input, open a new output file,
    copy the initial portion. (If the decompression write starts at the beginning,
    you actually don't even have an initial portion to copy.)

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    You face forward, or you face the possibility of shock and damage.
     
    Derk Gwen, Nov 16, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kobu
    Replies:
    10
    Views:
    629
    Keith Thompson
    Mar 4, 2005
  2. AB@
    Replies:
    2
    Views:
    1,378
  3. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    702
    James Kanze
    Jun 15, 2007
  4. philmasterplus

    Bypassing the EOF marker

    philmasterplus, Apr 19, 2008, in forum: C++
    Replies:
    2
    Views:
    431
    James Kanze
    Apr 19, 2008
  5. Jan Burse
    Replies:
    67
    Views:
    1,068
    Jan Burse
    Mar 14, 2012
Loading...

Share This Page