invalid lvalue in assignment

This is a discussion on invalid lvalue in assignment within the C Programming forums, part of the General Programming Boards category; When compile, the red line is error, invalid lvalue in assignment How to fix this? Code: #include <stdio.h> #include <stdlib.h> ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    27

    invalid lvalue in assignment

    When compile, the red line is
    error, invalid lvalue in assignment
    How to fix this?
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX 30
    
    int main()
    {
        int customerCount=0;
        char input[32];
        char drinks[MAX][10];
        char smallLarge[MAX][6];
        char hotCold[MAX][5];
        int i=0;
    
        printf("How many people are at your table?: ");
        fgets(input,32,stdin);
        sscanf(input,"%d",&customerCount);
    
        if(customerCount==0)
            {
            printf("END");
            exit(0);
            /*summary*/
            }
    
        printf("\n\nChoose what type of drink would you like.\n\n");
    
        while(customerCount!=0)
            {
            do
                {
                printf("Coffee, Tea, Cocoa, or Ovaltine?: ");
                fgets(input,32,stdin);
                sscanf(input,"%s",drinks[i]);
                }
            while(strlen(drinks[i])==0);
    
            do
                {
                printf("Small or Large?: ");
                fgets(input,32,stdin);
                sscanf(input,"%s",smallLarge);
                }
            while(strlen(smallLarge[i])==0);
    
            do
                {
                printf("Hot or Cold?: ");
                fgets(input,32,stdin);
                sscanf(input,"%s",hotCold);
                }
            while(strlen(hotCold[i])==0);
    
            if(strcmp(drinks[i],"None")=0)
                {
                printf("BILL");
                exit(0);
                /*print bill*/
                }
            }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,616
    The = should be ==.
    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
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,926
    Just a FYI.
    If you look at the line strcmp(drinks[i],"None")=0, there are two "sides":
    Left side: strcmp(drinks[i],"None")
    Right side: 0
    The left side is called lvalue.
    The right side is called rvalue.
    So the compiler basically says "you cannot assign 0 to strcmp(drinks[i],"None")".

    And as laserlight points out, comparison is done using ==, not =. That's assign.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. :523: error: invalid lvalue in assignment
    By nasim751 in forum C Programming
    Replies: 10
    Last Post: 04-14-2008, 04:08 AM
  2. invalid lvalue in assignment
    By saipkjai in forum C++ Programming
    Replies: 8
    Last Post: 06-21-2007, 03:19 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. invalid lvalue in assignment
    By antonis in forum C Programming
    Replies: 8
    Last Post: 10-09-2005, 12:00 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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