Thread: Assigning Variable to arry

  1. #1
    Vicked
    Guest

    Assigning Variable to arry

    Hi

    I cant get VC++ to assign a value to an array, I have an array declared something like this:


    typedef struct
    {
    TCHAR Name[10];
    TCHAR Species[10];
    } VCValues;

    VCValues VCList
    {
    "ABCDEFGHIJ", "KLMNOPQRST";
    };

    Or something, syntax is probably wrong

    I try to assign a value like so:

    VCList[1].Name = "ABCDEFGHIJ";

    What am I doing wrong?

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    VCValues foo= {"ABC", "DEF"};

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    watch that the TCHAR (which is a typedef of char) is probably null terminated. That is will need an extra element to hold the end character (\0). ie you are allocating too much into the array.

    also try sprintf() to fill the array
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You need an equals (=), don't put a semi-colon inside the {}, and you need 11 chars to hold "ABCDEFGHIJ".

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assigning an object variable to a constant reference
    By Canadian0469 in forum C++ Programming
    Replies: 18
    Last Post: 11-10-2008, 10:48 AM
  2. C variable
    By webstarsandeep in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 01:26 AM
  3. Assigning Binary Value to a Variable
    By JAYMAN in forum C Programming
    Replies: 2
    Last Post: 11-06-2005, 01:24 PM
  4. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  5. Variable assigning Functions
    By emus21 in forum C Programming
    Replies: 4
    Last Post: 11-09-2003, 01:13 AM