Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!rochester!uhura.cc.rochester.edu!elmo From: elmo@uhura.cc.rochester.edu (Eric Cabot) Newsgroups: comp.lang.pascal Subject: Re: Can I declare an array using a var in the index? Keywords: array Message-ID: <9597@ur-cc.UUCP> Date: 22 Sep 90 23:29:03 GMT References: <1994@ac.dal.ca> Organization: Harry Faversham Memorial Heap Space Lines: 38 In article <1994@ac.dal.ca> limoges@ac.dal.ca writes: >I want to write a program which generates 2D arrays of size n x n after n has >been input from the keyboard by the user running the program. My debugger If you can stand to have one of the dimensions (either row or col) pre- defined then why not declare a type of that array size and an array of pointers to that type. There isn't really very much overhead in having that array of pointers. Addressing the elements in your matrix isn't particularly messy or difficult. Here are some program fragments to show you what I mean: TYPE col_arr:record of col: array[1..200] of integer; end; VAR row:array[1..200] of ^col_arr; ... readln(nrows); for i:=1 to nrows do new(row[i]^); ... row[5]^.col[5]:=25; (*sets item at row 5, col 5 to the value 25*) ... I've used this basic strategy quite a bit for programs that don't know ahead of time how much memory a given user has on his computer. You can also further complicate matters by making the col a linked list, or a linked list of small arrays. I hope this helps out. -- =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= Eric Cabot | elmo@{uhura | db1}.cc.rochester.edu "insert your face here" | elmo@uordbv.bitnet =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=