home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!gatech!news.ans.net!nynexst.com!jsd
- From: jsd@nynexst.com (Joseph Delotto)
- Subject: allocating 2-d array
- Message-ID: <1992Dec22.185523.4732@nynexst.com>
- Sender: news@nynexst.com (For News purposes)
- Organization: NYNEX Science & Technology, Inc.
- Date: Tue, 22 Dec 92 18:55:23 GMT
- Lines: 20
-
- Sorry if this is too simple, but I can't find a good example in
- any books. I want to dynamically allocate a 2-d array for a
- variable defined as:
-
- int **myarray;
-
- where the dimensions = nrows,ncols. Currently I'm using the
- following code:
-
- myarray = (int **) malloc ((unsigned) nrows*sizeof(int*));
- for(i=0;i<=nrows;i++)
- myarray[i] = (int *) malloc ((unsigned) ncols*sizeof(int));
-
- which seems to work ok but looks awfully sloppy. Is there any
- way to get the whole thing done in one shot?
-
- Thanks for any help,
-
- Joe DeLotto
- jsd@nynexst.com
-