
-----------------------------------
ReN3g@de
Fri Jan 30, 2004 3:18 pm

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:

Jeff
password
1
2
1

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:

var chrName: string
var line: string
var nIn : int
var countO : int := 0
var pass : string
cls
put "What is your character's name?"
get chrName
open : nIn, chrName, get
loop
    get : nIn, line
    exit when eof (nIn)
end loop
loop
    put "Enter password"
    get pass
    if pass = line then
        exit
    else
    end if
    countO += 1
    exit when countO=4
end loop
put "You've inputed the incorrect answer too man times"


I've attached the entire program so far

-----------------------------------
sport
Fri Jan 30, 2004 3:47 pm


-----------------------------------
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. 
open: fln,flname,read,mod,seek,write

-----------------------------------
shorthair
Fri Jan 30, 2004 4:15 pm


-----------------------------------
If your intersted in learning binary files , look at my FP , very stong use of them in all 4 of the apps

-----------------------------------
Delos
Fri Jan 30, 2004 4:19 pm


-----------------------------------
Nice plug there shorthair!

Here is dodge's tutorial for records.  These are particularly useful when doing binary file stuff

[url=http://www.compsci.ca/v2/viewtopic.php?t=2325]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*).

-----------------------------------
Method
Fri Jan 30, 2004 4:53 pm


-----------------------------------
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

-----------------------------------
Delos
Fri Jan 30, 2004 5:40 pm


-----------------------------------
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... :roll: .

-----------------------------------
shorthair
Fri Jan 30, 2004 6:31 pm


-----------------------------------
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
