home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19394 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.2 KB  |  50 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!demos!news-server
  3. From:  stas@itco.msk.su (Stas Strizhakov)
  4. Subject: Arrays with variable dimensions?
  5. Date: Tue, 5 Jan 1993 17:25:47 GMT
  6. Reply-To: stas@itco.msk.su
  7. Organization: I.T. Co., Moscow, Russia.
  8. Sender: news-server@kremvax.hq.demos.su
  9. Message-ID: <ACRISIhiZA@itco.msk.su>
  10. Lines: 38
  11.  
  12. In article <1992Dec26.220736.22177@news.ysu.edu>
  13. Subject: [NEWS] Arrays with variable dimensions?
  14. ah017@yfn.ysu.edu (John B. Lee) writes:
  15.  
  16. >Is it possible to create an array that would change size according
  17. >to user input?
  18.  
  19.         May be try to use *alloc/realloc pair.
  20.  
  21. For example,
  22.  
  23. void main () {
  24.         int size; int *ar; int *newAr;
  25.         size = 1; ar = malloc (size*sizeof(int));
  26.         while (size++ < 1000) {
  27.                 newAr = realloc (ar, size*sizeof(int));
  28.                 if (newAr != NULL) ar = newAr;
  29.         }
  30.         free (ar);
  31. }
  32.  
  33.         I used this method when wrote editor with automatically
  34. extending buffer
  35.  
  36. --
  37.  
  38.                     Regards,
  39.                                 Stas.
  40. ???????????????????????????????????????????????????????????????????????????????
  41.                         There's so many different worlds
  42.                         So many different suns
  43. Stas K. Strizhakov                I.T.Co                Programmer
  44. phone    : (7-095)262-4381        fax     : (7-095)924-3775
  45. e-mail    : stas@itco.msk.su
  46.  
  47.  
  48.  
  49.  
  50.