| attempt to read past eof error 
 
	 
	
		| Author | Message |   
		| cloust 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 9:17 am    Post subject: attempt to read past eof error |  |   
				| 
 |  
				| in my program, you can create an account, edit it, login, etc. I was  trying to make a search function in the program, where you can lookup your account without having to login. I can succesfully look up the first account in my record, but if I try to lookup anything else, I get an error saying that it attempted to read past eof, and I have no idea why its doing this. 
 here is the code, I was wondering if anyone could see what I'm missing.
 
 	  | code: |  	  | proc sear
open : filenumber, "WoWaccounts.dat", get
 %%%
 put "enter your accout name: " ..
 get search %search inquiry
 loop
 number += 1 %used to count which account the array is on
 
 for i : 1 .. number
 
 get : filenumber, accountc (i).name
 get : filenumber, accountc (i).address
 get : filenumber, accountc (i).pnumber
 get : filenumber, accountc (i).ccard
 get : filenumber, accountc (i).username
 
 
 if accountc (i).username = search then
 
 put "Name: ", accountc (i).name
 put "Adress: ", accountc (i).address
 put "Phone Number: ", accountc (i).pnumber
 put "Credit card: ", accountc (i).ccard
 put "Username: ", accountc (i).username
 coo := 2 % used for an exit condition
 
 exit
 elsif accountc (i).username not= search then
 put "I'm sorry, there is no user with that name"
 end if
 
 end for
 if coo = 2 then
 exit
 end if
 end loop
 close : filenumber
 end sear
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Delos 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 9:36 am    Post subject: (No subject) |  |   
				| 
 |  
				| You've read the 'end of file' (eof).  Make sure your source file has the correct number of lines (1 for each of the get: statements). Additionally, you may want to edit your code a bit and try incorporate this sort of routine instead:
 
 
 	  | code: |  	  | 
var file : int
 var temp : string
 
 open : file, "myfile.txt", get
 loop
 exit when eof (file)
 get : file, temp
 put temp
 end loop
 close : file
 
 | 
 
 The 'exit when eof (file)' is the key line.  See if you can figure out how to incorporate that into your code (hint, you'll only be using 1 get: statement).
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| cloust 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 10:03 am    Post subject: (No subject) |  |   
				| 
 |  
				| well, after trying the method you showed, I realised that turing was writing the input to my files wrong. if, say for my phone number, I put (812) 888 3456, it would write each item after the space to a new line. I have no idea why its doing that.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Delos 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 11:11 am    Post subject: (No subject) |  |   
				| 
 |  
				| Sounds familiar.  Post the code for that part of your proggie, I'll take a look at it. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| cloust 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 11:21 am    Post subject: (No subject) |  |   
				| 
 |  
				| 	  | code: |  	  | type account :
record
 name : string
 address : string
 pnumber : string
 ccard : string
 username : string
 password : string
 
 end record
 
 proc create
 
 
 
 %the procedure for creating an account
 
 
 for num : 1 .. 1
 colorback (90)
 locate (10, 27)
 get accountc (num).name : *
 locate (16, 29)
 get accountc (num).address : *
 locate (20, 39)
 get accountc (num).pnumber : *
 locate (24, 42)
 get accountc (num).ccard : *
 locate (28, 45)
 get accountc (num).username : *
 locate (32, 33)
 accountc (num).password := getpass
 
 end for
 
 
 open : filenumber, "WoWaccounts.dat", put, seek, mod
 %put information into a file
 for a : 1 .. 1
 
 seek : filenumber, *
 put : filenumber, accountc (a).name
 put : filenumber, accountc (a).address
 put : filenumber, accountc (a).pnumber
 put : filenumber, accountc (a).ccard
 put : filenumber, accountc (a).username
 put : filenumber, accountc (a).password
 end for
 
 close : filenumber
 end create
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Delos 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 1:02 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Hmm...strange.  I just tried out your code and it works fine for me.  (I did have to recreate the pertinent undeclared variables though...). I noticed that you're using seek and mod - these are more commonly used with write: as opposed to put:.  It does its job though.
 You may want to consider, instead of using them, to read the whole file into a flexy array, get the new info, then put: all of that to the file.  Technically a little slower, but might solve your problem (which for some reason doesn't happen to me).
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| cloust 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 29, 2006 2:07 pm    Post subject: (No subject) |  |   
				| 
 |  
				| okie, I found the tutorial on flexible arrays, so I'll see what I can do. thanks for the help! |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| redrenagade 
 
 
 
 
 | 
			
				|  Posted: Sat Feb 04, 2006 6:17 pm    Post subject: (No subject) |  |   
				| 
 |  
				| This might help, try to put the "exit when eof" line at the end of your loop. I think your program is exiting when it reaches the end of file, then, for some reason, trying to read the next line of code within the loop. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		|  |  
 |