unable to reset and move the pointer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karthigeyantp
    New Member
    • Jul 2008
    • 22

    unable to reset and move the pointer

    hi,

    i have a problem in resetting and unable to move the pointer in the text file using seekg()function in c++. what to do ??
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    R u checking what the seekg is returning and whether the file is having that much bytes in it...


    raghu

    Comment

    • karthigeyantp
      New Member
      • Jul 2008
      • 22

      #3
      Originally posted by gpraghuram
      R u checking what the seekg is returning and whether the file is having that much bytes in it...


      raghu
      when i reset it to starting point by
      file.seekg(0,io s::beg);
      after this through file.tellg() it shows this number 4294967295
      so it has not resetted, i don't know what to do. my max file size is 65751180.

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by karthigeyantp
        when i reset it to starting point by
        file.seekg(0,io s::beg);
        after this through file.tellg() it shows this number 4294967295
        so it has not resetted, i don't know what to do. my max file size is 65751180.

        Usually it dosent behave that way.
        I tried a small piece of code and it printed the value properly.
        Can you post the piece of code on how u are doing the seek and tell?


        Raghu

        Comment

        • karthigeyantp
          New Member
          • Jul 2008
          • 22

          #5
          my loc value= 6575910

          file.clear();
          file.seekg(0,io s::beg);
          locat=distance. tellg();
          cout<<"locat= "<<locat<<" \n";
          file.seekg(loc) ;
          loc1=fil.tellg( );
          cout<<"after move"<<loc1;

          after resetting to staring point the tellg() is showing -1. After moveing to some position i.e loc=6575910. but after this the tellg() is showing 42949672951.

          Comment

          • TamusJRoyce
            New Member
            • Apr 2008
            • 108

            #6
            Please tell us the compiler & version you are trying to use. I've had this problem on MinGW gcc 3.4 (from dev-cpp). The MinGW from Codeblocks solved this for me, but I dunno if it would be a compiler problem for you or not...

            Comment

            • gpraghuram
              Recognized Expert Top Contributor
              • Mar 2007
              • 1275

              #7
              Originally posted by karthigeyantp
              my loc value= 6575910

              file.clear();
              file.seekg(0,io s::beg);
              locat=distance. tellg();
              cout<<"locat= "<<locat<<" \n";
              file.seekg(loc) ;
              loc1=fil.tellg( );
              cout<<"after move"<<loc1;

              after resetting to staring point the tellg() is showing -1. After moveing to some position i.e loc=6575910. but after this the tellg() is showing 42949672951.

              Why r u calling the clear() function as it is only for resetting the error state flags.
              Can you try this fater commenting the clear function call.

              Raghu

              Comment

              • karthigeyantp
                New Member
                • Jul 2008
                • 22

                #8
                Originally posted by gpraghuram
                Why r u calling the clear() function as it is only for resetting the error state flags.
                Can you try this fater commenting the clear function call.

                Raghu
                i tried without using the clear() fun.. also, but same result is comeing . i don,t know what to do.

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  4294967295 = 0xFFFFFFFF or -1 in 32 bits. The tell failed in all circumstances. This suggests that the seek failed (that is the most likely cause of the tell failing).

                  You need to work out why your seek failed. Since you are trying to seek to the start of the file which should work for pretty much any file it must be something else.

                  Have you verified that the file is actually open?
                  Have you stepped through the code using a debugger?

                  Comment

                  • karthigeyantp
                    New Member
                    • Jul 2008
                    • 22

                    #10
                    Originally posted by TamusJRoyce
                    Please tell us the compiler & version you are trying to use. I've had this problem on MinGW gcc 3.4 (from dev-cpp). The MinGW from Codeblocks solved this for me, but I dunno if it would be a compiler problem for you or not...
                    i am using gcc( 3.4.2) compiler in linux

                    Comment

                    • gpraghuram
                      Recognized Expert Top Contributor
                      • Mar 2007
                      • 1275

                      #11
                      As suggested by Banfa its better you debug the code and find the issue.
                      As told by me i tried a small piece of code and it worked.

                      Raghu

                      Comment

                      • karthigeyantp
                        New Member
                        • Jul 2008
                        • 22

                        #12
                        Originally posted by gpraghuram
                        R u checking what the seekg is returning and whether the file is having that much bytes in it...


                        raghu
                        i am new to linux may i know how to debug the c++ code

                        Comment

                        • gpraghuram
                          Recognized Expert Top Contributor
                          • Mar 2007
                          • 1275

                          #13
                          Originally posted by karthigeyantp
                          i am new to linux may i know how to debug the c++ code


                          You have to use gdb to debug the code.
                          gdb <exename>
                          Better read the help of gdb before starting to work with gdb.


                          Raghuram

                          Comment

                          Working...