Thread: Using Arrays as Sources of Data for Arrays in a Structure - How?

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    15

    Using Arrays as Sources of Data for Arrays in a Structure - How?

    I am having a great deal of trouble getting the following to work.

    I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.

    I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.

    Might someone please show me how to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)

    Thanks in advance for any help!



    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int comm = 10;
    	int targ = 5;
    	int death;
    	struct AI_WORDS
    	{
    	string word;
    	int MAL;
    	};
    	string Comwords[]={"cat","dog","elephant"};
    	int ComMAL[]={10,10,10};
    	int TheNum = sizeof Comwords/(sizeof Comwords[0]);
    	AI_WORDS Com_WM[3];
    	//AI_WORDS *Com_WM=new AI_WORDS[TheNum];
    	for(int i =0;i<TheNum;i++)
    	{
    	Com_WM->word[i]=Comwords[i];
    	Com_WM->MAL[i]=ComMAL[i];
    	};

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The array is Com_WM, not word.
    Code:
    Com_WM[i].word = Comwords[i];

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    15
    Gracias!

    Danke shoen!

    (Thanks!)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure of arrays
    By zeebo17 in forum C Programming
    Replies: 2
    Last Post: 06-23-2010, 10:11 AM
  2. How to structure my arrays?
    By worldder in forum C++ Programming
    Replies: 10
    Last Post: 04-07-2010, 10:43 AM
  3. Structure arrays...
    By krsauls in forum C Programming
    Replies: 9
    Last Post: 05-02-2007, 12:35 AM
  4. help with structure arrays
    By mapunk in forum C Programming
    Replies: 8
    Last Post: 11-17-2005, 08:44 AM
  5. displaying data from a structure of arrays
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 03-14-2002, 12:35 PM