C
Alastair Dallas
awd at dbase.UUCP
Tue Mar 7 12:17:42 AEST 1989
In article <1989Feb28.170504.17123 at utzoo.uucp>, henry at utzoo.uucp (Henry Spencer) writes:
> In article <9501 at bloom-beacon.MIT.EDU> yphotons at 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<n; i++)
p[i] = 0.0;
...
free(p);
What's the big deal?
/alastair/
More information about the Comp.lang.c
mailing list