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. How to read file in reverse order?

How to read file in reverse order?

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

    I wand to read file form end to the start of the file... byte by byte... can anyone suggest me or provide me any sample code that helps me...??????:confused::confused: thanks in advance... Savcejana Sukinobavanthu Ashok.

    A D 2 Replies Last reply
    0
    • A ashokbngr

      I wand to read file form end to the start of the file... byte by byte... can anyone suggest me or provide me any sample code that helps me...??????:confused::confused: thanks in advance... Savcejana Sukinobavanthu Ashok.

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      You could do it with a for loop, find the length of the file in bytes (using a while loop or otherwise) then do a for loop but backwards for(int i=FileLength; i>=0; i -=1) { //Read the file i number of bytes }

      1 Reply Last reply
      0
      • A ashokbngr

        I wand to read file form end to the start of the file... byte by byte... can anyone suggest me or provide me any sample code that helps me...??????:confused::confused: thanks in advance... Savcejana Sukinobavanthu Ashok.

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

        Why do you need to do this? I would suggest reading the file into a buffer, and then reversing that buffer. It'll be much faster this way.


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        M 1 Reply Last reply
        0
        • D David Crow

          Why do you need to do this? I would suggest reading the file into a buffer, and then reversing that buffer. It'll be much faster this way.


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          or reading the file and inserting in the buffer at the beginning instead of at the end.


          Maximilien Lincourt Your Head A Splode - Strong Bad

          D 1 Reply Last reply
          0
          • M Maximilien

            or reading the file and inserting in the buffer at the beginning instead of at the end.


            Maximilien Lincourt Your Head A Splode - Strong Bad

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

            Maximilien wrote:

            or reading the file and inserting in the buffer at the beginning...

            Which is how files are normally read. :confused:


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            M 1 Reply Last reply
            0
            • D David Crow

              Maximilien wrote:

              or reading the file and inserting in the buffer at the beginning...

              Which is how files are normally read. :confused:


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              I don't know, if I have to read a file in order, I will read a line ( for example, a text file ) and add the newly read line at the end of my "buffer". if I want to read the file in reverse order, I might read the file in order and then sort internally what I have read, or try to read the file in reverse (from the end ) and add to the buffer at the end.


              Maximilien Lincourt Your Head A Splode - Strong Bad

              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