Board index » delphi » HELP: ARRAYS!!

HELP: ARRAYS!!

I am just starting to learn pascal and would appretiate any help that you
can give me on the following problem of mine:

I need to read in a list of integers from a file.  The numbers are arranged
in 4 colomns.  The first row going down represents someone's id number and
the next three colomns are different statistics about them.  The last 3
colomns must be arrays referring to the 1st colomn(the Index in this
program).  

 The trouble that I am having is that there are currentsly 40 rows(going
across) and the first number in these rows (the id number) is listed more
than once in the file.  Since the id number can be any number from 1 to 20
I did a for loop.  However my loop stops reading information after the 20th
row, and I want it to read all 40 rows and whenever it encounters a
repeated id I want it to ad the info in that row to the info in a previous
row containing the same id.

I know it may sound complicated, or maybe it sounds easy as pie to you, but
I would really appretiate your help as I hope to gain more knowledge in
pascal.

Thanks again,

Eric

 

Re:HELP: ARRAYS!!


Quote
"Eric Mauskopf" <Eric.Mausk...@worldnet.att.net> wrote:
>I need to read in a list of integers from a file.  The numbers are arranged
>in 4 colomns.  The first row going down represents someone's id number and
>the next three colomns are different statistics about them.  The last 3
>colomns must be arrays referring to the 1st colomn(the Index in this
>program).  
> The trouble that I am having is that there are currentsly 40 rows(going
>across) and the first number in these rows (the id number) is listed more
>than once in the file.  Since the id number can be any number from 1 to 20
>I did a for loop.  However my loop stops reading information after the 20th
>row, and I want it to read all 40 rows and whenever it encounters a
>repeated id I want it to ad the info in that row to the info in a previous
>row containing the same id.

This looks more like an algorithmic and file reading problem rather
than an array problem.  Since the id may be from 1 to 20, that does
not dictate reading from your file for only 20 times (as your for loop
does).  You will want to read all items in the line.  In this case,
you will need to use a while not eoln() construct while counting
exactly how many times you do read for purposes of your array.  Also,
you'll need to know how many records to expect .  As far as reading
from the same ID and adding, you'll need a record construct, storing
the ID # of items in the array and the array itself.  when you
encounter a new ID, you'll need to search if the ID already exists,
and if it does, add the information.  Otherwise, you'll add it to the
bottom of your information.

Re:HELP: ARRAYS!!


-=[ In:eric.mauskopf@worldnet was heard to say... ]=-

 In> I need to read in a list of integers from a file.  The numbers are
 In> arranged in 4 colomns.  The first row going down represents someone's
 In> id number and the next three colomns are different statistics about
 In> them.  The last 3 colomns must be arrays referring to the 1st
 In> colomn(the Index in this program).  

 In> The trouble that I am having is that there are currentsly 40
 In> rows(going across) and the first number in these rows (the id number)
 In> is listed more than once in the file.  Since the id number can be any
 In> number from 1 to 20 I did a for loop.  However my loop stops reading
 In> information after the 20th row, and I want it to read all 40 rows and
 In> whenever it encounters a repeated id I want it to ad the info in that
 In> row to the info in a previous row containing the same id.

If you did a FOR/DO loop from 1 to 20, it will loop 20 times, obviously. Why
do you even think you need to use a FOR/DO loop?

        -- Kim Forwood --

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\
  $           Kim Forwood  <kim.forw...@access.cn.camriv.bc.ca>          %
  %              http://goodship.cn.camriv.bc.ca/~kforwood/              $
  $         For what purpose is life, if one cannot live freely?         %
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/

___ Blue Wave/QWK v2.20

Other Threads