unable to reset and move the pointer
Question posted by: karthigeyantp
(Newbie)
on
July 21st, 2008 12:25 PM
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 ??
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
July 22nd, 2008 01:25 AM
# 2
|
Re: unable to reset and move the pointer
R u checking what the seekg is returning and whether the file is having that much bytes in it...
raghu
|
|
July 22nd, 2008 06:01 AM
# 3
|
Re: unable to reset and move the pointer
Quote:
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,ios::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.
|
|
July 22nd, 2008 06:13 AM
# 4
|
Re: unable to reset and move the pointer
Quote:
Originally Posted by karthigeyantp
when i reset it to starting point by
file.seekg(0,ios::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
|
|
July 22nd, 2008 06:49 AM
# 5
|
Re: unable to reset and move the pointer
my loc value= 6575910
file.clear();
file.seekg(0,ios::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.
|
|
July 22nd, 2008 07:38 AM
# 6
|
Re: unable to reset and move the pointer
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...
|
|
July 22nd, 2008 07:51 AM
# 7
|
Re: unable to reset and move the pointer
Quote:
Originally Posted by karthigeyantp
my loc value= 6575910
file.clear();
file.seekg(0,ios::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
|
|
July 22nd, 2008 08:52 AM
# 8
|
Re: unable to reset and move the pointer
Quote:
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.
|
|
July 22nd, 2008 09:44 AM
# 9
|
Re: unable to reset and move the pointer
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?
|
|
July 23rd, 2008 07:57 AM
# 10
|
Re: unable to reset and move the pointer
Quote:
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
|
|
July 23rd, 2008 08:16 AM
# 11
|
Re: unable to reset and move the pointer
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
|
|
July 23rd, 2008 09:22 AM
# 12
|
Re: unable to reset and move the pointer
Quote:
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
|
|
July 24th, 2008 01:22 AM
# 13
|
Re: unable to reset and move the pointer
Quote:
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
Not the answer you were looking for? Post your question . . .
184,041 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top C / C++ Forum Contributors
|