home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16764 < prev    next >
Encoding:
Text File  |  1992-11-18  |  1.4 KB  |  48 lines

  1. Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!pitt.edu!pitt!fahad
  2. From: fahad@cs.pitt.edu (Fahad A Hoymany)
  3. Newsgroups: comp.lang.c
  4. Subject: 2-D Arrays Problem Solved
  5. Message-ID: <17514@pitt.UUCP>
  6. Date: 19 Nov 92 02:06:46 GMT
  7. Article-I.D.: pitt.17514
  8. Sender: news@cs.pitt.edu
  9. Organization: Univ. of Pittsburgh Computer Science
  10. Lines: 36
  11.  
  12. Thanks to all of the people who responded to my question on passing 2-D
  13. arrays of varying sizes to a function.  In particular, the answer below
  14. which sums up all the other ones was provided by Shawn Willden.
  15.  
  16. /******** Some of those who responded *********************
  17. From: hwu@scf.usc.edu (Hung-Yao Wu)
  18. From: Pete Holsberg <pjh@mccc.edu>
  19. From: swillden@icarus.weber.edu (Shawn Willden)
  20. From: joe@monroe.pilot.dmg.ml.com (Milamber)
  21. From: jamshid@emx.cc.utexas.edu (Jamshid Afshar)
  22. From: William Kaufman <wkaufman@us.oracle.com>
  23. /*********************************************************/
  24. int main()
  25. {
  26.  int a[2][2], b[3][3];
  27.  a[1][1] = 1234;
  28.  b[1][1] = 33;
  29.  printf("Before, a[1][1] = %d\n", a[1][1]);
  30.  printf("Before, b[1][1] = %d\n", b[1][1]);
  31.  
  32.  proc(&a[0][0], 2, 2);
  33.  proc(&b[0][0], 3, 3);
  34.  printf("After, a[1][1] = %d \n", a[1][1]);
  35.  printf("After, b[1][1] = %d \n", b[1][1]);
  36. }
  37. /*****************************************************/
  38. int proc(int *a, int r, int c)
  39. {
  40.  int i, j;
  41.  
  42.  for (i=0; i<r; i++)
  43.    for (j=0; j<c; j++) 
  44.       a[c*i+j] = 88;
  45. }
  46.  
  47. ..Fahad@speedy.cs.pitt.edu
  48.