Thread: Ultra basic question, got a mind block going on

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    42

    Ultra basic question, got a mind block going on

    Hey all,

    The following code causes the error "incompatible types" on the line "Osiris.name = "Osiris";"

    Code:
    struct player {
    
        char name[10];
        int chosenNumbers[6];
    
    };
    
        struct player Osiris;
        Osiris.name = "Osiris";
    I've used strings and structs, in a very similar manner to this before. I've checked my previous code, but can't see what's going wrong.... it's identical to my code before but this time it's throwing that error. I don't get it...

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You cannot do a straight assign of a value to an array in that way. You would have to use (in this case) strcpy/strncpy, i.e.:
    Code:
    strcpy(Osiris.name,"Osiris");
    In the context of your original code, you are attempting to point the address of the array (which is fixed and not something you can change) to the address of the string literal "Osiris" which resides in the program's data segment somewhere.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    Yeah, sorry, I wrote that exact thing about 45 seconds ago, and was coming back to the thread to say nevermind lol.

    Cheers for the explanation on what's actually happening
    Last edited by osiris^; 10-09-2007 at 11:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Buddy Memory Allocation" Question
    By LedgeDrop in forum C++ Programming
    Replies: 1
    Last Post: 07-10-2007, 08:17 AM
  2. Basic question about GSL ODE func RK4
    By cosmich in forum Game Programming
    Replies: 1
    Last Post: 05-07-2007, 02:27 AM
  3. Basic question about RK4
    By cosmich in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2007, 02:24 AM
  4. A very basic question
    By AshFooYoung in forum C Programming
    Replies: 8
    Last Post: 10-07-2001, 03:37 PM