Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 getting a certain part of the text file
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ReN3g@de




PostPosted: 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:
code:

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:
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



game.t
 Description:
my game

Download
 Filename:  game.t
 Filesize:  3.97 KB
 Downloaded:  266 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
sport




PostPosted: Fri Jan 30, 2004 3:47 pm   Post subject: (No 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.
code:
open: fln,flname,read,mod,seek,write
shorthair




PostPosted: Fri Jan 30, 2004 4:15 pm   Post subject: (No subject)

If your intersted in learning binary files , look at my FP , very stong use of them in all 4 of the apps
Delos




PostPosted: Fri Jan 30, 2004 4:19 pm   Post subject: (No 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*).
Method




PostPosted: Fri Jan 30, 2004 4:53 pm   Post subject: (No 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
Delos




PostPosted: Fri Jan 30, 2004 5:40 pm   Post subject: (No 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... Rolling Eyes .
shorthair




PostPosted: Fri Jan 30, 2004 6:31 pm   Post subject: (No 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: