Computer Science Canada getting a certain part of the text file |
Author: | ReN3g@de [ Fri Jan 30, 2004 3:18 pm ] | ||||
Post subject: | getting a certain part of the text file | ||||
ok so im making a little game that u can save ur progress and level etc. i know how to save to file but i want to load one certain line at a time. This is what the text file looks like:
now i want to load the second line, password, only so i can compare it with data entered by the user. its a password thing if u havent figured that out yet hah. Here's what i have for code:
I've attached the entire program so far |
Author: | sport [ Fri Jan 30, 2004 3:47 pm ] | ||
Post subject: | |||
You can not change only one line. You will have to get whole file and then make the changes and write back to the file. You will erase the previous version in the process. Or you can learn how to use binary files and records where you can change the record only without affecting the whole file.
|
Author: | shorthair [ Fri Jan 30, 2004 4:15 pm ] |
Post subject: | |
If your intersted in learning binary files , look at my FP , very stong use of them in all 4 of the apps |
Author: | Delos [ Fri Jan 30, 2004 4:19 pm ] |
Post subject: | |
Nice plug there shorthair! Here is dodge's tutorial for records. These are particularly useful when doing binary file stuff Here! And I'm sure that shorhair's programme is wonderfully commented so that you won't have a single problem reading through it (*wink*wink*). |
Author: | Method [ Fri Jan 30, 2004 4:53 pm ] |
Post subject: | |
He's not trying to change a line, fellows, just compare a line of text to user input. Don't go confusin' the boy with binary. This should do it: var pass,pline : string var filestream, yada : int := 0 put "Input your password:".. get pass open : filestream,"filename.txt",get loop exit when eof(filestream) get : filestream,pline : * if pline = pass then yada := 1 exit end if end loop close : filestream if yada = 1 then put "Correct password entered!" else put "You poor sucker..." end if |
Author: | Delos [ Fri Jan 30, 2004 5:40 pm ] |
Post subject: | |
Hmm...not bad Method. You seem to have forgotten to mention that he needs to make sure that the pwd found matches the UserName indicated. Otherwise that works. Wouldn't hurt to learn about binary. I mean, we all know how well Turing handles it... ![]() |
Author: | shorthair [ Fri Jan 30, 2004 6:31 pm ] |
Post subject: | |
I was unaware that a tutorial was out , im sorry about that one , i thought it was the next best thing , but for a referance mine uses records and binary writing , the turorial should d oyou fine , binary is the way to go , its really good for comparisons , it made it easy when i was searching for certain employees in my payroll , but you cant manually edit a binary file from its orogin , becasue when teh program opens it , it expects it to be a certain length , and cotain certain amount of characters , unlike txt files |