Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can't update text file

Can't update text file

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    :confused:This should be a no brainer. I am using Visual C++ 6.0. Because I want to use fseek() I declare a file of FILE* filename and then use filename = fopen(path, "r+"). I can read from the file but when I try to write (using fprintf() and fwrite()) to the file nothing changes in the file I am reading from and trying to write to. I have also tried "rt+". I receive no errors. Is there something basic I'm not aware of? Buck

    T _ 2 Replies Last reply
    0
    • B BuckBrown

      :confused:This should be a no brainer. I am using Visual C++ 6.0. Because I want to use fseek() I declare a file of FILE* filename and then use filename = fopen(path, "r+"). I can read from the file but when I try to write (using fprintf() and fwrite()) to the file nothing changes in the file I am reading from and trying to write to. I have also tried "rt+". I receive no errors. Is there something basic I'm not aware of? Buck

      T Offline
      T Offline
      Tombo
      wrote on last edited by
      #2

      See if this helps! When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for “update”). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.

      1 Reply Last reply
      0
      • B BuckBrown

        :confused:This should be a no brainer. I am using Visual C++ 6.0. Because I want to use fseek() I declare a file of FILE* filename and then use filename = fopen(path, "r+"). I can read from the file but when I try to write (using fprintf() and fwrite()) to the file nothing changes in the file I am reading from and trying to write to. I have also tried "rt+". I receive no errors. Is there something basic I'm not aware of? Buck

        _ Offline
        _ Offline
        _psh_
        wrote on last edited by
        #3

        Hi, According to the MSDN library at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_crt\_fopen.2c\_.\_wfopen.asp they say "When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired." So it looks like you will have to reset the open file pointer to the appropriate position before switching between reading and writing operations. If possible, it may be more convenient for you to read and write using separate sessions. Hope this helps. Paul

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups