home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!pitt.edu!pitt!fahad
- From: fahad@cs.pitt.edu (Fahad A Hoymany)
- Newsgroups: comp.lang.c
- Subject: 2-D Arrays Problem Solved
- Message-ID: <17514@pitt.UUCP>
- Date: 19 Nov 92 02:06:46 GMT
- Article-I.D.: pitt.17514
- Sender: news@cs.pitt.edu
- Organization: Univ. of Pittsburgh Computer Science
- Lines: 36
-
- Thanks to all of the people who responded to my question on passing 2-D
- arrays of varying sizes to a function. In particular, the answer below
- which sums up all the other ones was provided by Shawn Willden.
-
- /******** Some of those who responded *********************
- From: hwu@scf.usc.edu (Hung-Yao Wu)
- From: Pete Holsberg <pjh@mccc.edu>
- From: swillden@icarus.weber.edu (Shawn Willden)
- From: joe@monroe.pilot.dmg.ml.com (Milamber)
- From: jamshid@emx.cc.utexas.edu (Jamshid Afshar)
- From: William Kaufman <wkaufman@us.oracle.com>
- /*********************************************************/
- int main()
- {
- int a[2][2], b[3][3];
- a[1][1] = 1234;
- b[1][1] = 33;
- printf("Before, a[1][1] = %d\n", a[1][1]);
- printf("Before, b[1][1] = %d\n", b[1][1]);
-
- proc(&a[0][0], 2, 2);
- proc(&b[0][0], 3, 3);
- printf("After, a[1][1] = %d \n", a[1][1]);
- printf("After, b[1][1] = %d \n", b[1][1]);
- }
- /*****************************************************/
- int proc(int *a, int r, int c)
- {
- int i, j;
-
- for (i=0; i<r; i++)
- for (j=0; j<c; j++)
- a[c*i+j] = 88;
- }
-
- ..Fahad@speedy.cs.pitt.edu
-