Thread: l-value error with structures

  1. #1
    Unregistered
    Guest

    Question l-value error with structures

    i have a data structure called details with a fiels called address which holds a char array of 100, but if i try the following:

    details.address = temp;

    i get the error:

    error C2106: '=' : left operand must be l-value

    temp is also a char array of 100.

    anyone know how to fix this or how to acomplish it another way??

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Use strcpy() to copy strings, you cannot use the assignment operator.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    9

    Talking answer


    accoring to c definition you dont have any operator to operate in array directly, so if you want to copy use strcpy functions,l-value is basically value that can be can be modified .

  4. #4
    Registered User PutoAmo's Avatar
    Join Date
    Mar 2002
    Posts
    72
    The reaon why you get error "left operand must be lvalue" is that the assignment operator needs an lvalue as the left operand.

    details.address is the name of an array. In C, the name of an array is a constant. And a constant cannot be an lvalue. It would be like coding:

    5 = a + b;

    5 is a constant, and a constant cannot be an lvalue.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM