Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-05-2007, 10:32 PM   PM User | #1
mad_girl
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
mad_girl is an unknown quantity at this point
eof bit not set

why such two easy lines don work
char c;
while(!file.eof ())
{ file.read(c,1); cout<<c; }
the loop is infinite i don know why the eof bit is not set or what
mad_girl is offline   Reply With Quote
Old 10-05-2007, 10:46 PM   PM User | #2
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
I don't see what type of object file is, but if it is what I think it is, file.read is a seek operation. You need to advance the pointer.
http://www.cplusplus.com/doc/tutorial/files.html
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 10-05-2007, 11:12 PM   PM User | #3
mad_girl
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
mad_girl is an unknown quantity at this point
i don understand what u mean by advancing my pointer!!!
mad_girl is offline   Reply With Quote
Old 10-08-2007, 03:09 PM   PM User | #4
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Did you read the linked article that explains what that means?
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 10-11-2007, 01:24 AM   PM User | #5
mad_girl
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
mad_girl is an unknown quantity at this point
that problem is done now
but i got another one,when file.tellg() return -1?
Code:
while(file.tellg()<=lastEnd)
{
	file.getline (temp,20,'=');
	if (strncmp(temp,varName.c_str(),varName.length())==0  )
	{
		file.getline (X,20);
		return true;
	}
	file.ignore(30,'\n');
}
when i debug this code and make it print lastEnd and file.tellg() values through the iteration of the loop every thing is fine until file.tellg() return -1 in the middle of the file so the loop doesn't end??!!!!!
mad_girl is offline   Reply With Quote
Old 10-11-2007, 02:47 PM   PM User | #6
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Why are you doing all these seek and pointer operations?
Are you moving back and forth in the stream or trying to skip to a certain position?

Also you seem to be combining seek operation with whole getline. I don't think that would work very well.

If you just need to read input forward-only and do something with it, you don't need all this. You can just read in a line at a time as a string and manipulate that string.

What are you trying to do exactly? Get pairs of things from a file using = or look for a certain string in the file, or ...?
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 10-11-2007, 07:51 PM   PM User | #7
mad_girl
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
mad_girl is an unknown quantity at this point
i'm trying to read a file on that form
someThing = someValue
and i don know that something in advance so i read it and compare it if that is it i take the value after '='.
i know i can do it with different way may be reading the hole line then getting parts of it ,but i wanna know what's wrong with this approach??
mad_girl is offline   Reply With Quote
Old 10-13-2007, 12:03 AM   PM User | #8
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Nothing "wrong" per se, but it's always best to keep things as simple as possible.
If you know, for example, that you have a file in a particular format, such as name/value pairs (name=value then a newline), you can just read it in line per line, do a string split on the equals sign, and compare the array(0) element.

If this in an ini file or a config file, there are probably routines to do what you're looking to do already made. It's rarely necessary to reinvent the wheel, unless there are no wheels out there that meet you needs, if that makes sense.
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:27 PM.


Advertisement
Log in to turn off these ads.