home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!demos!news-server
- From: stas@itco.msk.su (Stas Strizhakov)
- Subject: Arrays with variable dimensions?
- Date: Tue, 5 Jan 1993 17:25:47 GMT
- Reply-To: stas@itco.msk.su
- Organization: I.T. Co., Moscow, Russia.
- Sender: news-server@kremvax.hq.demos.su
- Message-ID: <ACRISIhiZA@itco.msk.su>
- Lines: 38
-
- In article <1992Dec26.220736.22177@news.ysu.edu>
- Subject: [NEWS] Arrays with variable dimensions?
- ah017@yfn.ysu.edu (John B. Lee) writes:
-
- >Is it possible to create an array that would change size according
- >to user input?
-
- May be try to use *alloc/realloc pair.
-
- For example,
-
- void main () {
- int size; int *ar; int *newAr;
- size = 1; ar = malloc (size*sizeof(int));
- while (size++ < 1000) {
- newAr = realloc (ar, size*sizeof(int));
- if (newAr != NULL) ar = newAr;
- }
- free (ar);
- }
-
- I used this method when wrote editor with automatically
- extending buffer
-
- --
-
- Regards,
- Stas.
- ???????????????????????????????????????????????????????????????????????????????
- There's so many different worlds
- So many different suns
- Stas K. Strizhakov I.T.Co Programmer
- phone : (7-095)262-4381 fax : (7-095)924-3775
- e-mail : stas@itco.msk.su
-
-
-
-
-