1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

LValue required for error !

Discussion in 'C' started by pratgupta, Feb 20, 2009.

  1. pratgupta

    pratgupta New Member

    Joined:
    Feb 20, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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;
       [B][I] c[0].cuisinename = "Italian" ;[/I][/B]
    
        c[0].d[0].dishid = 1;
        [B][I]c[0].d[0].dishname = "Dosa";[/I][/B]
        c[0].d[0].dishprice = 15.50;
        c[0].d[1].dishid = 2;
        [B][I]c[0].d[1].dishname = "Idly";[/I][/B]
        c[0].d[1].dishprice = 25.50;
        c[0].d[2].dishid = 3;
       [B][I] c[0].d[2].dishname = "Wada";
    [/I][/B]    c[0].d[2].dishprice = 30.00;
        c[0].d[3].dishid = 4;
        [B][I]c[0].d[3].dishname = "Sambhar";
    [/I][/B]    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.
     
    Last edited by a moderator: Feb 21, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    > 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.
     

Share This Page