Assigning Variable to arry

This is a discussion on Assigning Variable to arry within the Windows Programming forums, part of the Platform Specific Boards category; Hi I cant get VC++ to assign a value to an array, I have an array declared something like this: ...

  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,136
    VCValues foo= {"ABC", "DEF"};

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    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,666
    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, 09: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, 12: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, 12:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21