error in c++ progm

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • singharchi
    New Member
    • Aug 2009
    • 6

    error in c++ progm

    hello please solve this prob (LValue required)

    Code:
    void main()
    {
    
    int a=0;
    char *ptr[10]={" kanitkar","balagurushami","morishmano"};
    char str[20];
    clrscr();
    
    cout<<"enter name to search\n";
    cin>>str;
    
    for(a=0;a<3;a++)
    {
    
    if(!strcmp(str, *ptr[a]))
    
    {
    
    cout<<"book is found"<<endl;
    break;
    }
    ptr++;
    }
    if(a==3)
    cout<<"book not found";
    
    getch();
    }
    Last edited by Banfa; Aug 7 '09, 07:29 PM. Reason: A
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    On which line of your code do you get the error?

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      There is no LVALUE error in this code.

      The only error is using a char instead of a char* as a strcmp argument.

      Maybe you could explain your situation in a little more detail.

      Comment

      • singharchi
        New Member
        • Aug 2009
        • 6

        #4
        LValue required on line 15th

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          And by line 15 did you actually mean line 22

          ptr++;

          ?

          ptr is an array you can't perform arithmetic operations on an array.

          It is not even clear what you intend as you increment the array control variable else where (a++ in the loop).


          You whole program invokes undefined behaviour as you return void from main. main ALWAYS returns int.

          Comment

          • singharchi
            New Member
            • Aug 2009
            • 6

            #6
            thanx ... got mistakes and solved this prob

            Comment

            Working...