Two dementional array help
Author |
Message |
pinto
|
Posted: Tue Jun 13, 2006 4:17 pm Post subject: Two dementional array help |
|
|
Well, I'm writing a program that needs to read out of a datafile and store the information in two dementional arrays to be used later on in the program but i'm not having anyluck. The information in the text file thats being read will be formated like this;
Greg Wilson
34 54
With 100's more names and their numbers after that following the same format. The numbers taken from the data files also have to be able to be manipulated and put on the screen later.
My problem is that i can not figure out a way to get two dementional arrays to store what i need stored, and in such a way that i can easly get the number of goals (34) and number of assists(54) that Greg Wilson scored later on in the program.
I'd really appreciate it if somone could possibly throw out some ideas for me, or take the time to write a few lines of code out for me so that i can follow the logic necisary for this program to work,
Thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bored
|
Posted: Tue Jun 13, 2006 4:33 pm Post subject: (No subject) |
|
|
Well I don't see why you'd be using a 2-dimensional array. If you'd ask me I'd use a 1-dimensional array of records. A record incase you did not know is like a collection of variables each with there own type. Look it up in the turing help files or the tutorial section here for more info, and to learn how to use them. Now like any other type a record can be used as the type for an array. If you have an array of records that contains the names, goals, and assists of each person then you're problem is easy. Now if this is something your teacher assigned and he said to use 2-dimensional arrays, well then I have no idea how you'd efectively do that. |
|
|
|
|
|
Clayton
|
Posted: Tue Jun 13, 2006 4:34 pm Post subject: (No subject) |
|
|
why use a 2d array when you can use records instead? simply have a type player, which contains all the things the player has, a name, goals scored, and assists, much easier to use than trying to manipulate your 2d array to what you want to do |
|
|
|
|
|
Clayton
|
Posted: Tue Jun 13, 2006 4:35 pm Post subject: (No subject) |
|
|
damn u beat me to it check the Turing Walkthrough if you need to check up or learn about anything in the last two posts |
|
|
|
|
|
pinto
|
Posted: Tue Jun 13, 2006 4:47 pm Post subject: (No subject) |
|
|
Well unfortunatly it has to be two demential arrays. But actually i was thinking something like this,
var goal, assist, filenum : int
var name:string
open :filenum,"file.txt", get
loop
exit when eof
get :filenum, name
get :filenum,goal
get :filenum, assist
var name:array 1..2, 1..1 of int
name (1,1) := goal
name(2,1) := assist
end loop
close :filenum
Something like that. However the problem i'm running into here is getting the goal and assist varible from the datafile (because there on the same line). If anyone could help me with this problem or point out anyother problems they see with this it would be appreciated.
Thanks |
|
|
|
|
|
Clayton
|
Posted: Tue Jun 13, 2006 4:51 pm Post subject: (No subject) |
|
|
put the goal and assist "get" on one line eg.
code: |
open: fileStream,"PlayerStats.txt",get
loop
exit when eof(fileStream)
get: fileStream, playerName
get: fileStream, goals, assists
end loop
|
simple as that, check the Turing Walkthrough on file I/O if you have any problems with this
P.S. plz use [code ][/code] tags when posting |
|
|
|
|
|
|
|