Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   LValue required for error ! (http://www.go4expert.com/forums/lvalue-required-error-t16285/)

pratgupta 21Feb2009 02:07

LValue required for error !
 
Code:

#include<stdio.h>
#include<string.h>
#include<conio.h>
// dish structure
 struct dishdetails
    {
    int dishid;
    char dishname[25];
    float dishprice;
    } ;
  // cuisine structure
    struct cuisinedetails
    {
    int cuisineid;
    char cuisinename[25];
    struct dishdetails d[20];
    } ;

void display(struct cuisinedetails )        ;
 
void main()
{
 
struct cuisinedetails c[4];
clrscr();
 

    c[0].cuisineid= 1;
  c[0].cuisinename = "Italian" ;

    c[0].d[0].dishid = 1;
    c[0].d[0].dishname = "Dosa";
    c[0].d[0].dishprice = 15.50;
    c[0].d[1].dishid = 2;
    c[0].d[1].dishname = "Idly";
    c[0].d[1].dishprice = 25.50;
    c[0].d[2].dishid = 3;
  c[0].d[2].dishname = "Wada";
    c[0].d[2].dishprice = 30.00;
    c[0].d[3].dishid = 4;
    c[0].d[3].dishname = "Sambhar";
    c[0].d[3].dishprice = 45.00;
 
      display(c[0]);
getch();
}

void display(struct cuisinedetails a)
{
printf("\n%d\t%s ", a.cuisineid,a.cuisinename);
printf("\n\n%d\t%s\t%f", a.d[0].dishid,a.d[0].dishname,a.d[0].dishprice);
printf("\n%d\t%s\t%f", a.d[1].dishid,a.d[1].dishname,a.d[1].dishprice);
printf("\n%d\t%s\t%f", a.d[2].dishid,a.d[2].dishname,a.d[2].dishprice);
printf("\n%d\t%s\t%f", a.d[3].dishid,a.d[3].dishname,a.d[3].dishprice);
}



I am Getting errors Lvalue required for the bold lines.
wher I m tring to assign a String name in an array of characters.
Please help me out.

xpi0t0s 21Feb2009 14:11

Re: LValue required for error !
 
> c[0].cuisinename = "Italian"

cuisinename is defined as char[25] so the assignment operator won't work here. Use strcpy(), or define cuisinename as std::string which supports the assignment operator.


All times are GMT +5.5. The time now is 07:11.