Thread: string contents into structure help

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    string contents into structure help

    I have this problem where I want a persons name to be put into a structure. I have written the code like this but my compiler is telling me "Lvalue" is required. I dont know how to rectify this, can anyone tell me what I've done wrong?? Thanks in advance.

    Code:
    typedef struct
    {
                        
        char name[40];         
                   
    } details_t;
    
    
    
    int main (void)
    
    {
    details_t person;
    
    
    char name [40];
    
    printf("\nPlease enter the persons name: ");
    fflush(stdin);
    gets(name);
    
    name = person.name;
    
    
    fflush(stdin);
    getc(stdin);
    return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You use strcpy to copy strings.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    thanks, It works now.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    fflush(stdin); is undefined - see FAQ
    gets(name); - should not be used - see FAQ

    you should indent your code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 05:13 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM