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
    23,794
    You cannot assign to an array, so you should use strcpy() or strncpy().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,754
    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
    To be or not to be == true

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, 11:49 AM
  2. Lvalue required error
    By eklavya8 in forum C Programming
    Replies: 5
    Last Post: 01-03-2009, 03:47 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. Lvalue required, eh..
    By Linette in forum C++ Programming
    Replies: 13
    Last Post: 03-02-2002, 07:23 PM

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