TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: John Richardson
from: Bob Stout
date: 1998-08-16 17:40:44
subject: Dynamic Structs?

On , John Richardson (2:2502/60{at}fidonet.org) wrote: 

 > But, how do I create a variable number of structs, allocating the
 > memory when needed.
 >
 > int num_of_configs=atoi(argv[1]);        // for example
 >
 > // Mystery Code here please. :)

 > CONFIG  *c;

 >     c = malloc( sizeof( CONFIG) * num_of_configs);

 > Access with:

 >     c[config_num].element;

 > If you want to allocate or deallocate individual configs later on you 
 > will need either an array of pointers or to set-up a linked list.

John...

  An even easier way is to use either MDALLOC.C or AMALLOC.C from SNIPPETS.
Both implement multi-dimensional arrays of any arbitrary size and/or number
of dimensions. 


--- QM v1.00
* Origin: MicroFirm : Down to the C in chips (1:106/2000.6)
SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728 810
SEEN-BY: 639/252 670/213 218
@PATH: 30883/6 106/2000 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.