Computer Science Canada

Records

Author:  hskhan [ Mon Jun 16, 2003 5:01 pm ]
Post subject:  Records

How would i create / input / output data into a record?

Author:  PaddyLong [ Mon Jun 16, 2003 5:03 pm ]
Post subject: 

here is a very simple one that demonstrates what I think you are asking

code:

var person :
    record
        name : string
        age : int
    end record

person.name := "Paddy"
person.age := 17

put person.name, " is ", person.age, " years old"

Author:  Andy [ Mon Jun 16, 2003 5:14 pm ]
Post subject: 

ya you could also create an artifical type like that
type data:
record
name : string
age : int
end record

Author:  Andy [ Mon Jun 16, 2003 5:14 pm ]
Post subject: 

whoa paddylong, you indent even on compsci.ca?

Author:  hskhan [ Mon Jun 16, 2003 5:21 pm ]
Post subject: 

I need a record, and text file combo that checks if a record exists before. how can i check if the record has been added to the text file? Could you please help. Thanks.
So far I have :

code:

type playerRec :
    record
        User : string (5)
        PlayerScore : int
    end record
var rplayer : playerRec

var name : string
put "Name" ..
get name
var getname : string := ""
loop
    if length (name) <= 5 then

        rplayer.User := name
        var fout : int
        open : fout, "outputfile.txt", write, mod, seek
        seek : fout, *
        write : fout, rplayer
        close : fout
        put "Added"
        exit
    end if

end loop

Author:  PaddyLong [ Mon Jun 16, 2003 6:16 pm ]
Post subject: 

dodge_tomahawk wrote:
whoa paddylong, you indent even on compsci.ca?

I type it in turing and press f2 then copy and paste

I would say to read your entire file into an array of records (probably use a flexible array for this) then search through it to check if the data inside it is the same as any of the ones in the array

Author:  Andy [ Mon Jun 16, 2003 6:17 pm ]
Post subject: 

you should take the open satement out of the loop


: