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. Not able to Read Contents for File while Reading Huge Amount of data.

Not able to Read Contents for File while Reading Huge Amount of data.

Scheduled Pinned Locked Moved C / C++ / MFC
xml
7 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.
  • J Offline
    J Offline
    janaswamy uday
    wrote on last edited by
    #1

    Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.

    C P D L A 5 Replies Last reply
    0
    • J janaswamy uday

      Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      janaswamy uday wrote:

      file.read(buffer,100000);

      You should always check the return value of an API function call. See, for instance, the code sample in the _read documentation page[^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • J janaswamy uday

        Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.

        P Offline
        P Offline
        Paresh Chitte
        wrote on last edited by
        #3

        Try Using

        CStdioFile

        . Regards, Paresh.

        1 Reply Last reply
        0
        • J janaswamy uday

          Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.

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

          janaswamy uday wrote:

          if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))

          What you have posted will not even compile. That aside, this should be:

          if (! file.Open("C:\\users\\rakesh\\Desktop\\myText.xml", CFile::modeRead))

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          1 Reply Last reply
          0
          • J janaswamy uday

            Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            janaswamy uday wrote:

            if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
            {
            return false;
            }

            This means if you successfully open the file you return false instead of reading the file into your buffer.

            I must get a clever new signature for 2011.

            1 Reply Last reply
            0
            • J janaswamy uday

              Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.

              A Offline
              A Offline
              Andrew Brock
              wrote on last edited by
              #6

              It may or may not be causing this issue, but the stack has limited space, and allocating 100,000 TCHARs on the stack is not a good idea. you should instead use

              LPTSTR buffer = new TCHAR[100000];
              file.read();
              //process data
              delete []buffer;

              J 1 Reply Last reply
              0
              • A Andrew Brock

                It may or may not be causing this issue, but the stack has limited space, and allocating 100,000 TCHARs on the stack is not a good idea. you should instead use

                LPTSTR buffer = new TCHAR[100000];
                file.read();
                //process data
                delete []buffer;

                J Offline
                J Offline
                janaswamy uday
                wrote on last edited by
                #7

                Thank you very much Bruck. I will try with that.

                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