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. File Reading Issue

File Reading Issue

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 6 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.
  • V Offline
    V Offline
    VC_RYK
    wrote on last edited by
    #1

    Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK

    C S K B 4 Replies Last reply
    0
    • V VC_RYK

      Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Post some code.

      Cédric Moonen Software developer
      Charting control [v1.4] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • V VC_RYK

        Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK

        S Offline
        S Offline
        shaibee
        wrote on last edited by
        #3

        If you are using the same file object to read the file again, you need to seek the file pointer to beginning of file(BOF), before you read. This is so because you have read to End of File, and when you read again, it tries to read from current position of file pointer. You need to reset the current position to BOF. I dont know what language are u using but it would be something like file.Seek(0); or filestream.SeekBegin(); or something similar. Regards,

        Its never over !

        D 1 Reply Last reply
        0
        • V VC_RYK

          Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK

          K Offline
          K Offline
          kbshibukumar
          wrote on last edited by
          #4

          If you are reading something other than a text file (say, mp3 or mpeg), there can be multiple EOF in the same file. So it is a better idea to first calculate the size of the file and then read byte by byte. Shibu

          1 Reply Last reply
          0
          • S shaibee

            If you are using the same file object to read the file again, you need to seek the file pointer to beginning of file(BOF), before you read. This is so because you have read to End of File, and when you read again, it tries to read from current position of file pointer. You need to reset the current position to BOF. I dont know what language are u using but it would be something like file.Seek(0); or filestream.SeekBegin(); or something similar. Regards,

            Its never over !

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            shaibee wrote:

            If you are using the same file object to read the file again, you need to seek the file pointer to beginning of file(BOF), before you read.

            The OP said the file was closed before attempting to open and read from it again.

            "Love people and use things, not love things and use people." - Unknown

            "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

            1 Reply Last reply
            0
            • V VC_RYK

              Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK

              B Offline
              B Offline
              Bram van Kampen
              wrote on last edited by
              #6

              Use a seek function. If you opened with fopen(...) you use fseek(F,0,SEEK_SET) to rewind it to the beginning. :)

              Bram van Kampen

              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