I’m simulating inheritance in C, but I’m not so familiar with the language. Below is some of the code. Visual Studio has an error message for emp.name=n which says:
expression must be a modifiable lvalue.
How do I change it so it can be modified?
typedef struct {
char name[20];
double salary;
} Employee;
Employee newEmployee(char n[], double s)
{
Employee emp;
emp.name=n;
emp.salary=s;
return emp;
}
You need to copy the data from
ntoEmployee.name:However, if
nis not NULL-terminated, you will run into problems. Use the following code to guarantee thatemp.namewill be a NULL-terminated string: