I'm getting an error:
expression must be a modifiable lvalue at line,
obj.name = ptr->name
I have tried to make obj an array type object like so
for(int j=0 ;j<1;j++)
{
obj[j].id = ptr->id;
obj[j].balance= ptr->balance;
obj[j].name = ptr->name; //still getting error here.
obj[j].nic = ptr->nic;
}
return(obj);
}
but that has not worked either.
if i comment the error out and pass just three remaining values it should work but i receive garbage values after the first out put.
here is the original code:
#include<iostream>
using namespace std;
struct bank
{
int id, nic;
float balance;
char name[20];
};
bank search(bank* );
void main()
{
bank data[2],mobj;
for(int i=0;i<2;i++)
{
cout<<"enter name: ";
cin>>data[i].name;
cout<<"enter id: ";
cin>>data[i].id;
cout<<"enter balance : ";
cin>>data[i].balance;
cout<<"enter nic : ";
cin>>data[i].nic;
}
mobj=search(data);
cout <<"balance of customer no. "<<mobj.balance<<endl;
cout<<"id is" <<mobj.id<<endl;
cout<< "nic is"<<mobj.nic<<endl;
system("pause");
}
bank search(bank *ptr)
{
int id;
cout<<"enter value you want to serch"<<endl;
cin>>id;
bank obj;
for(int i=0 ; i<2 ;i++)
{
if(ptr->id == id)
{
break;
}
ptr++;
}
obj.id = ptr->id;
obj.balance= ptr->balance;
obj.name = ptr->name; //error in this line(obj must be modifiable value)
obj.nic = ptr->nic;
return(obj);
}
please help as you see fit!