#1
  1. It Doesn't Work!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Slovenia
    Posts
    112
    Rep Power
    12

    Resume copying a file


    I made a program which should copy a file, log the position and remember where it broke so it could be able to continue copying at that position when you start it again. The only problem is that when I putc(), it doesn't write it to the file immediately, so if I break the program the output file remains empty. I tried with bigger files (25M) and it wrote approx. 8M. How can I force the program to write directly to disk, not to the stack or whatever it does? :)
    Last edited by Loser; September 7th, 2003 at 12:47 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    11
    fflush(fp); causes internal buffers to send their contents to the final destination immediately. Give that a shot and see how it works for you.
  4. #3
  5. It Doesn't Work!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Slovenia
    Posts
    112
    Rep Power
    12
    That works. Again, so simple answer. :) Thanks.
  6. #4
  7. It Doesn't Work!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Slovenia
    Posts
    112
    Rep Power
    12
    If I fflush() will the file pointer stay on its current position or is it moved to beginning or somewhere else?
  8. #5
  9. No Profile Picture
    Dinesh_P_V
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    India
    Posts
    259
    Rep Power
    0

    Resume copying a file


    fflush flushes the buffer.
    Usually by fputc the characters are put into buffer and written to memory when the buffer fills.
    So when we call fflush all the contents in buffer are written to the disk memory immediately. So there is nothing related to fp position and fflush. fp will point to the same position before the call to fflush

    -Murugesan
  10. #6
  11. It Doesn't Work!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Slovenia
    Posts
    112
    Rep Power
    12
    OK, thanks for the answers.

IMN logo majestic logo threadwatch logo seochat tools logo