Results 1 to 3 of 3

Thread: how build a dynamic array from a struture?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Unhappy how build a dynamic array from a struture?

    imagine that you have these struct:
    Code:
    struct Person
    {
        char Name[255];
        int age;
    };
    and you create a variable array:
    Person a[20];
    but then you only need 3. how can i change it?
    i try several things and read some info, but i only get errors
    i understand that i'm using C code with some C++, but i don't know C++(for now).. after i finish C i will
    these sample is for see if i can do something... i'm tired loking for something and nothing works
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: how build a dynamic array from a struture?

    There are many different types of containers in the standard library. Take a look at the vector class for instance (http://http://www.cplusplus.com/refe...vector/vector/)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: how build a dynamic array from a struture?

    Quote Originally Posted by Atheist View Post
    There are many different types of containers in the standard library. Take a look at the vector class for instance (http://http://www.cplusplus.com/refe...vector/vector/)
    i did a mistake in link
    sorry i read that before and i never understand that, maybe when i learn C++ i understand
    and i resolve it:
    1 - we must create a pointer variavel;
    2 - we must point to NULL;
    3 - now we do:
    (the pointer name can be a subclass and then the struture)
    PointerName = (vartype*) realloc (PointerName, NumberofIndices * sizeof(vartype));
    the vartype can be a structure
    4 - when we don't need the pointer we must free the mesmory:
    free(PointerName);
    5 - if your windows gives an error and close the program, then see if you have used another pointer without recreate it
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width