Thread: automatic creation of structures and deleting them

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    61

    automatic creation of structures and deleting them

    Hi all!

    How to automatically create structures (the aliens in this code are capable to muliply) and delete them? Is the only way to change the value of "number" in this code and re-define the struct part? What if Alien[55] is killed and at the same time Alien[56] and Alien[57] are multiplying?

    Code:
    some headers....
    
    int number;
    number = 100;
    
    struct alien{
     int energy;
     int health;
    }Alien[number]
    
    int main(void){
    
    ...game...
    
    }
    Thanks in advance for ideas!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could use a linked list. Actually a double linked list would probably be better, because it's easier to chop out random pieces if you need to.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    61
    Thanks!
    The aliens are happy now, since there's no problem with the multiplying

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  2. Replies: 3
    Last Post: 10-31-2006, 02:15 AM
  3. Problem Deleting Part of a Linked List
    By Chronom1 in forum C++ Programming
    Replies: 5
    Last Post: 07-15-2004, 09:54 AM