Lvalue required

This is a discussion on Lvalue required within the C Programming forums, part of the General Programming Boards category; I'm not sure why I get this error... Code: typedef struct pcb { char name[11]; int pclass; int priority; } ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    278

    Lvalue required

    I'm not sure why I get this error...

    Code:
    typedef struct pcb {
    	char name[11];
    	int  pclass;
    	int  priority;
    } pcb;
    
    int main() {
      pcb *new_pcb = allocate_pcb(); //allocates memory for structure
    
      new_pcb->pclass = 1;
      new_pcb->priority = 2;
      new_pcb->name = "newpcb1";  //error on this line : Lvalue required
    }
    how do I assign the value of name inside the structure?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,157
    You cannot assign to an array, so you should use strcpy() or strncpy().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by gmrnetworks View Post
    You can't create structure name s the same as the reference of structure. You have define the other name.
    if you mean that

    Code:
    typedef struct dcb dcb;
    is incorrect - you are wrong;
    you can make a dcb type synonim of the struct dcb type
    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. lvalue required as increment operand compile error
    By canadatom in forum C Programming
    Replies: 8
    Last Post: 06-13-2009, 12:49 PM
  2. Lvalue required error
    By eklavya8 in forum C Programming
    Replies: 5
    Last Post: 01-03-2009, 04:47 PM
  3. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 05:33 PM
  5. Lvalue required, eh..
    By Linette in forum C++ Programming
    Replies: 13
    Last Post: 03-02-2002, 08:23 PM

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