home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16091 < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.9 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!zaphod.mps.ohio-state.edu!wupost!gumby!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!prancer.eche.ualberta.ca!niu
  3. From: niu@prancer.eche.ualberta.ca (Shaohua Niu)
  4. Subject: Two-dimensional Array
  5. Message-ID: <1992Nov6.163315.20337@kakwa.ucs.ualberta.ca>
  6. Sender: news@kakwa.ucs.ualberta.ca
  7. Nntp-Posting-Host: prancer.eche.ualberta.ca
  8. Organization: University Of Alberta, Edmonton Canada
  9. X-Newsreader: Tin 1.1 PL3
  10. Date: Fri, 6 Nov 1992 16:33:15 GMT
  11. Lines: 39
  12.  
  13. I am trying to use dynamic memory allocation for two-dimesional
  14. matrices and the code fragment is as follows:
  15.  
  16. typedef float **MATRIX;
  17.  
  18. MATRIX calloc_matrix(int row, int col)
  19. {
  20.   int i;
  21.   MATRIX mat;
  22.   mat = calloc(row, sizeof(float *));
  23.   if (mat==NULL) exit(1);
  24.   for (i=0; i<row; i++) {
  25.     mat[i] = calloc(col, sizeof(MATRIX));
  26.     if (mat[i]==NULL) exit(1);
  27.   }
  28.    return mat;
  29. }
  30.  
  31. when this is called with row=9 and col=9, the fucntion works for the
  32. pointer mat[0] to mat[6], but for mat[7], it exited abnormally to DOS,
  33. with an error message saying memory allocation error, and the DOS
  34. is halted. It seems that memory allocation of mat[i] is in conflict
  35. with the operating system codes resides in the memory. Actually this 
  36. piece of code is quite close to the example in the FAQ. But why does
  37. it not work. I am using Microsoft C/C++ 7.0 under DOS5.0.
  38.  
  39. Can anybody kindly point out my problem?
  40.  
  41. Thanx in advance.
  42.  
  43. --
  44.  
  45.        |        ------------------------------------------------------------  
  46.   | ---+----    Shaohua Niu           |    
  47.  /     |        Dept. of Chem. Eng.   |  Email: niu@prancer.eche.ualberta.ca  
  48.   -----+-----   Univ. of Alberta      |  Phone: (403) 432-7803 (Home)         
  49.        |        Canada, T6G 2G6       |         (403) 492-2971                
  50.        |        -------------------------------------------------------------
  51.   
  52.