Thread: Structs and Error C2106

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    24

    Structs and Error C2106

    I receive error C2106 (Compiler Error C2106 (C++))

    on these 2 lines:

    Code:
    data.buddy = buddyname;
    	data.message = "AAA";
    these are the relevant declarations at the beginning of the method:

    Code:
    guchar buddyname[MAX_BUDDYNAME_LENGTH+1];
    	struct tapData data;
    	struct tapData *p = &data;
    and this is my struct defined at the top of my code:

    Code:
    struct tapData {
    	char buddy[20];
    	char message[200];
    };
    the guchar buddyname is set in the code. I'm confused as to why I can't assign either value?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm a bit confused myself. Why are you posting this in the C forum, instead of the C++ forum?

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because you can't assign to arrays. To put characters into a character array, use strcpy or similar.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    As the poster said:

    Code:
    strcpy(data.message,"AAA");
    This copies the string AAA into data.message, and appends the null at the end of the 3 characters.

    ------------
    Beginner Computer Programming
    teaching computer programming to beginners using C

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    24
    Ah, thank you.

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    24
    Ignore, I can't spell or read. X.X
    Last edited by Dest; 04-13-2010 at 08:21 AM.

Popular pages Recent additions subscribe to a feed

Tags for this Thread