l-value error with structures

This is a discussion on l-value error with structures within the C Programming forums, part of the General Programming Boards category; i have a data structure called details with a fiels called address which holds a char array of 100, but ...

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

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