Thread: Error msg: "invalid lvalue in assignment"

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    3

    Error msg: "invalid lvalue in assignment"

    Hi everyone, this is my first time using the forum.

    I get the error msg "invalid lvalue in assignment". The line it refers to is as follows:
    Code:
    for(counter1=counter-5;counter1<=counter+5;counter1++){if(CONTACTS[counter1][0]=j && CONTACTS[counter1][1]=j_voisine){
    counter2=counter2+1;                                                                                                       }
                                                          }
    'counter' and 'counter1' have been declared outside main() and the code above is called within main(). I have used 'counter' as follows:
    Code:
    if(CONTACTS[counter-1][0]!=0 && (CONTACTS[counter-1][0]!=1052 || CONTACTS[counter-1][0]!=1053))
    and there was no problems.

    Has anybody encountered anything like this before?

    Thanks,

    Mike00800

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't see what is wrong in your code, but "invalid lvalue in assignment" usually means that "the compiler can't figure out what it's assigning to", and usually it's caused by trying to do "stupid" things like:
    Code:
       int i, j;
       ... 
       i + 1 = j;
    What is "CONTACTS"?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    73
    if(CONTACTS[counter1][0] = j && CONTACTS[counter1][1] = j_voisine
    i suppose it suld be == not =
    by using = u r assignig j to CoNTACTS[........er1][0] .......

    wat r u doin in this???? plssss tell wat r j and j_visine......
    if u wanna equate replace = with ==
    Last edited by ElemenT.usha; 11-07-2007 at 08:26 AM.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    3
    Hi Mats,

    Thanks for your help. "CONTACTS" is an int array that contains the list of pairs of grains that are in contact with each other i.e. 'j' and 'j_voisine'.

    1 5
    1 8
    2 27
    etc.

    I'm at a complete loss as I've perfromed similar operations before without any trouble

    Mike00800

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    3
    Hi ElemenT.usha,

    If I replace '=' with '==' as you suggested, do I need to replace '!=' with '!==' ???
    Stupid question, I know

    mike00800

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, you use one equal to assign something. Two equals to compare something. I didn't notice that the if-statement was suspicious, I think this is the right thing. !== is not a valid token in C.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lvalue rvalue discussion
    By George2 in forum C++ Programming
    Replies: 18
    Last Post: 03-04-2008, 05:48 AM
  2. A non-const reference may only be bound to an lvalue?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2007, 06:42 PM
  3. how to use reference for lvalue
    By jabka in forum C++ Programming
    Replies: 9
    Last Post: 04-22-2007, 02:08 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM