C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 5th, 2005, 10:28 PM
blitz00 blitz00 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 6 blitz00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 54 sec
Reputation Power: 0
using eof twice with same file

i was testing something out and used eof twice with the same txt file.
so means i open the txt file, use a loop to read all data inside the txt with eof.

then i close the loop and use eof again with the same txt. but this time it will
return nothing (i.e if i ask it to output something, nothing comes out).
Is the because in the first loop, i already ended reading the file, so the 2nd time it just
has nothing to read?

Reply With Quote
  #2  
Old May 5th, 2005, 11:52 PM
af4life af4life is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 af4life User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by blitz00
i was testing something out and used eof twice with the same txt file.
so means i open the txt file, use a loop to read all data inside the txt with eof.

then i close the loop and use eof again with the same txt. but this time it will
return nothing (i.e if i ask it to output something, nothing comes out).
Is the because in the first loop, i already ended reading the file, so the 2nd time it just
has nothing to read?


yes it is.

Reply With Quote
  #3  
Old May 6th, 2005, 01:08 AM
blitz00 blitz00 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 6 blitz00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 54 sec
Reputation Power: 0
oh ok then.
so what should i use to overcome such problem.

Reply With Quote
  #4  
Old May 6th, 2005, 10:44 AM
ShadowCoder ShadowCoder is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: Ottawa
Posts: 20 ShadowCoder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 12 sec
Reputation Power: 0
Quote:
Originally Posted by blitz00
oh ok then.
so what should i use to overcome such problem.

Reset your reading pointer back to the start of the file.

Reply With Quote
  #5  
Old May 7th, 2005, 04:47 AM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
you could just use fread() and see what value it returns, if it's 0, then that means there was nothing for it to read (meaning you're at an EOF condition)....
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #6  
Old May 7th, 2005, 05:53 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
B-Con, that doesn't solve his problem. That approach would also only work once. What you need to do is something like:
Code:
 #include <fstream>
 using std::ifstream;
 
 int main()
 {
 ifstream infile("c:\\file.txt");
 
 char c;
 
 while (c = infile.get() != EOF)
 {
 //process character
 }
 
 infile.seekg(0, ios::beg); //reset reading pointer back to beginning of file
 
 
  while (c = infile.get() != EOF)
  {
  //process character again
  }
 infile.close();
 }

Reply With Quote
  #7  
Old May 8th, 2005, 06:03 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
Quote:
Originally Posted by ubergeek
B-Con, that doesn't solve his problem. That approach would also only work once. What you need to do is something like:
Code:
. . . 

my bad, I didn't understand the question....

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > using eof twice woth same file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT