string contents into structure help

This is a discussion on string contents into structure help within the C Programming forums, part of the General Programming Boards category; I have this problem where I want a persons name to be put into a structure. I have written the ...

  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,185
    You use strcpy to copy strings.

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

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

    you should indent your code
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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-26-2003, 11:03 PM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM

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