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. Problem in Reading File.

Problem in Reading File.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 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.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, i am reading a file with help of CStdioFile using while loop and read the file till file reached end of file,in the file somewhere  symbol exist,when reading this line with ReadString ,while loop becomes infinite loop and not return and application goes in notresponding state. please tell me how can i read the full file with this symbol or how can i remove this symbol from file before reading the file. thanks in advance.

    C S 2 Replies Last reply
    0
    • L Le rner

      Hi all, i am reading a file with help of CStdioFile using while loop and read the file till file reached end of file,in the file somewhere  symbol exist,when reading this line with ReadString ,while loop becomes infinite loop and not return and application goes in notresponding state. please tell me how can i read the full file with this symbol or how can i remove this symbol from file before reading the file. thanks in advance.

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

      Please post some relevant code.

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

      L 1 Reply Last reply
      0
      • C Cedric Moonen

        Please post some relevant code.

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

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #3

        CStdioFile file;

        CString str="";
        file.Open(file\_name,CFile::modeRead,0);
        
        while(file.end)
        {
        	file.ReadString(str);
        }
        file.Close();
        
        C 1 Reply Last reply
        0
        • L Le rner

          CStdioFile file;

          CString str="";
          file.Open(file\_name,CFile::modeRead,0);
          
          while(file.end)
          {
          	file.ReadString(str);
          }
          file.Close();
          
          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Le@rner wrote:

          while(file.end)

          I don't know where the "end" is coming from (I never used CStdioFile in fact), but if you check the documentation of ReadString[^], you can see that the function returns FALSE when the end of file was reached. You should try to use that.

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

          L 1 Reply Last reply
          0
          • C Cedric Moonen

            Le@rner wrote:

            while(file.end)

            I don't know where the "end" is coming from (I never used CStdioFile in fact), but if you check the documentation of ReadString[^], you can see that the function returns FALSE when the end of file was reached. You should try to use that.

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

            L Offline
            L Offline
            Le rner
            wrote on last edited by
            #5

            if i do this ,function not read the full file and return when this symbol occur becoz here ReadFile return 0,but i want to read full file data.

            C 1 Reply Last reply
            0
            • L Le rner

              if i do this ,function not read the full file and return when this symbol occur becoz here ReadFile return 0,but i want to read full file data.

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

              Sorry, your sentence is not clear at all :confused:. There's no ReadFile function, I guess you are talking about ReadString ? Furthermore, the function doesn't read the complete file but only one line, so it is normal that the function return before the end of the file. You have to call it repeatedly until the function returns FALSE.

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

              1 Reply Last reply
              0
              • L Le rner

                Hi all, i am reading a file with help of CStdioFile using while loop and read the file till file reached end of file,in the file somewhere  symbol exist,when reading this line with ReadString ,while loop becomes infinite loop and not return and application goes in notresponding state. please tell me how can i read the full file with this symbol or how can i remove this symbol from file before reading the file. thanks in advance.

                S Offline
                S Offline
                SnowHow
                wrote on last edited by
                #7

                There are several issues with what is going on here.. After looking the code its important to note the file.end is not doing what you want it to do. If you look at the definition of the data member it is returning an enumeration to the end of the file. It is not whether or not you are currently at the EOF. Also the methods you are using STOP on a EOF character because you are reading in the default text mode. You should be opening the file in binary read mode " CFile::typeBinary". Because of the special characters I would suggest that you tseek the end of file get the length of the file and then do a for loop to retrieve the data out of the file.

                S 1 Reply Last reply
                0
                • S SnowHow

                  There are several issues with what is going on here.. After looking the code its important to note the file.end is not doing what you want it to do. If you look at the definition of the data member it is returning an enumeration to the end of the file. It is not whether or not you are currently at the EOF. Also the methods you are using STOP on a EOF character because you are reading in the default text mode. You should be opening the file in binary read mode " CFile::typeBinary". Because of the special characters I would suggest that you tseek the end of file get the length of the file and then do a for loop to retrieve the data out of the file.

                  S Offline
                  S Offline
                  Shivanand Gupta
                  wrote on last edited by
                  #8

                  Dear SnowHow, i have observe same result.

                  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