Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!elroy!hacgate!ashtate!dbase!awd From: awd@dbase.UUCP (Alastair Dallas) Newsgroups: comp.lang.c Subject: Re: C Summary: Malloc and pointers Message-ID: <27@dbase.UUCP> Date: 7 Mar 89 02:17:42 GMT References: <1256@dukeac.UUCP> <9743@smoke.BRL.MIL> <9501@bloom-beacon.MIT.EDU> <1989Feb28.170504.17123@utzoo.uucp> Organization: Ashton Tate Devlopment Center Glendale, Calif. Lines: 30 In article <1989Feb28.170504.17123@utzoo.uucp>, henry@utzoo.uucp (Henry Spencer) writes: > In article <9501@bloom-beacon.MIT.EDU> yphotons@athena.mit.edu (Sun Warrior) writes: > >I would like to know how to set an array (float) to a certain size... > >... I would first like to be able to type in the size and > >then set the array... > > You can't. With certain (unhelpful) exceptions, the dimensions of C arrays > must be constants. You can get much the same effect using malloc() and > pointers, although it is more complicated. It's not very complicated at all: float *p; int i; int n; printf("Enter the size of the array:"); scanf("%d", &n); p = (float *) calloc(n, sizeof(float)); for (i=0; i