Ultra basic question, got a mind block going on

This is a discussion on Ultra basic question, got a mind block going on within the C Programming forums, part of the General Programming Boards category; Hey all, The following code causes the error "incompatible types" on the line "Osiris.name = "Osiris";" Code: struct player { ...

  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,806
    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 12:36 PM.

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, 09:17 AM
  2. Basic question about GSL ODE func RK4
    By cosmich in forum Game Programming
    Replies: 1
    Last Post: 05-07-2007, 03:27 AM
  3. Basic question about RK4
    By cosmich in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2007, 03:24 AM
  4. A very basic question
    By AshFooYoung in forum C Programming
    Replies: 8
    Last Post: 10-07-2001, 04:37 PM

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