Results 1 to 8 of 8
  1. #1
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool

    [HELP] Saving Char* Arrays in Structure.

    I AM HAVING PROBLEMS WILLING A STRUCTURE WITH CHAR* [] and getting them back to text. When i put it in MessageBoxA() it Compiles but then it crashed at that location. When in PrintRightText() it just dont draw Anything.



    Structures HERE


    [PHP]struct sItem
    {
    char* Name;
    char** Options;
    int* Value;
    bool Selectable;
    sItem(char* NAME, char** OPTIONS, int* VALUE, bool SELECTABLE)
    {
    Name=NAME;
    Options=OPTIONS;
    Value=VALUE;
    Selectable=SELECTABLE;
    }
    ~sItem()
    {}
    };

    typedef struct {
    char* Name;
    int noItems;
    int totHeight;
    sItem** Items;
    int Selected;
    } sTab;
    [/PHP]

    The Adding FUNCTIONS

    [PHP]
    void cMenu::AddTab(char* name, bool selected)
    {
    TABS[noTabs]->Name = name;
    TABS[noTabs]->Selected = selected;
    TABS[noTabs]->noItems = noTempitems;
    TABS[noTabs]->totHeight = temptotHeight;
    TABS[noTabs]->Items = tempItems;
    noTempitems=temptotHeight=0;
    this->tempItems=(sItem **)malloc(10);
    for (int i=0; i<10; i++) this->tempItems[i]=(sItem *)malloc(sizeof(sItem));
    noTabs++;
    totHeight=(noTabs*30);
    }

    void cMenu::AddItem(char* Item_Name, char** Options, int* DefaultValue)
    {
    tempItems[noTempitems]=new sItem(Item_Name, Options, DefaultValue, true);
    noTempitems++;
    temptotHeight=(noTempitems*16);
    }[/PHP]

    FILL THE STRUCTURES HERE
    [php]char* Options[] = {"WEE", "WEE1", "WEE2"};
    pMenu->AddText("TEXTXY" , "HEY IT IS WORKING");
    pMenu->AddItem("Item 2", Options, &A[1]);
    pMenu->AddItem("Item 3", Options, &A[2]);

    pMenu->AddTab("Tab 1", true);
    [/PHP]

    AND NOT THE DRAW STUFFY


    [PHP]for (int i=0; i<this->noTabs;i++)
    {
    for (int o=0; o<(this->TABS[i]->noItems) ;o++)
    {
    int val=(this->TABS[i]->Items[o]->Value)?(*this->TABS[i]->Items[o]->Value):0;
    if (this->TABS[i]->Items[o]->Options){

    char* texy = this->TABS[i]->Items[o]->Options[val];

    PrintRightText(pFont,posi0+3, posi1+(o*15), 0xffccccff, texy);
    }
    }
    }[/PHP]
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  2. #2
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    guess no one here knows about this
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  3. #3
    scimmyboy's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Location
    http://mpgh.net MPGHCash: $442,596,199
    Posts
    5,649
    Reputation
    26
    Thanks
    894
    My Mood
    Happy
    thats cuz nobody wants to help mpgh anymore LOL

  4. #4
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    Quote Originally Posted by scimmyboy View Post
    thats cuz nobody wants to help mpgh anymore LOL
    I am not MPGH.. i am just a simple D3D coder .
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  5. #5
    GodHack2's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    645
    Reputation
    38
    Thanks
    762
    My Mood
    Amused
    recreating hans's ay





    beat this bitches ^^^^^^^

    Current Stats : Bored :/


    Respect list :
    Crash !
    Gordon'
    Markoj

  6. #6
    Gordon`'s Avatar
    Join Date
    Dec 2007
    Gender
    male
    Posts
    283
    Reputation
    24
    Thanks
    325
    there are local and global variables. using local variables is not very useful cause they are gone after the function call

    i said be careful with pointers in another thread. i would use memcpy/strcpy to copy the names/text values/etc into the structure.

    btw:
    Code:
    this->tempItems=(sItem **)malloc(10);
    this only allocates memory for 10 bytes not for 10 items
    Last edited by Gordon`; 01-16-2011 at 11:17 PM.


  7. The Following User Says Thank You to Gordon` For This Useful Post:

    why06 (01-17-2011)

  8. #7
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,305
    Reputation
    170
    Thanks
    2,194
    My Mood
    Flirty
    Good eye Gordon!

    I see you try to allocate memory for them here, but this does not work. Your only returning a pointer to the allocated memory.
    Code:
    for (int i=0; i<10; i++) this->tempItems[i]=(sItem *)malloc(sizeof(sItem));
    So all you ended up doing is saving pointers in those 10 bytes you allocated.

    To delare an an array of sItem simply do it like any other data type
    Code:
    int* intArray;
    intArray = new int[20]; //will create array of 20 ints
    so for sItems it would be
    Code:
    sItem* itemArray;
    itemArray = new sItem[some_number_here];
    Now itemArray will point to that allocated memory.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  9. The Following User Says Thank You to why06 For This Useful Post:

    topblast (01-17-2011)

  10. #8
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    I i will do that to make it little more safe, but menu Options still not working
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development