C

Robert D. Silverman bs at linus.UUCP
Wed Mar 1 00:24:16 AEST 1989


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
:normally I would have done it like this
:
:float array [size]
:
:but the thing is I would first like to be able to type in the size and
:then set the array . I tried this by using scanf statement and then
:the float but that did not work. help
:
:yphotons at athena.mit.edu


This is rather easy. Declare 'array' to be a pointer to a float, then
call malloc to allocate the memory space. e.g.

float *array

array = (float*) malloc(size* sizeof(float));

etc.

Bob Silverman



More information about the Comp.lang.c mailing list