# Structure problem

Printable View

• 12-18-2008
lolguy
Structure problem
I was studying today structure i understand but i was trying to make the code smaller and stuff but i get 2 error

d:\c_lessons_tutrials_made_by_me\test\1lolz.cpp(26 ) : error C2106: '=' : left operand must be l-value
d:\c_lessons_tutrials_made_by_me\test\1lolz.cpp(27 ) : error C2106: '=' : left operand must be l-value

anyway here the code
Code:

```#include <stdio.h> struct employee {         char name[101];     char postion[4];         char postion2[7];         char address[101];         int age;         float salary; }; /*Now for functions prototype*/ struct employee read_emp_age(); struct employee read_emp(); puttingfunction(); struct employee read_emp_salary(); print_emp_asker(struct employee emp); /*>>>>>>>>>>>>>>>>>>>*/ puttingfunction(){ fputs("Please Enter your num: ",stdout); return 0; } print_emp_asker(struct employee emp) { int x; struct employee emp2; emp.postion="Age"; emp2.postion2="Salary"; puts("DO you want salary or age or both? for both (3) for salary(2) for age press(1)"); scanf("%d",&x); switch(x) { case 1: emp=read_emp_age();//to get the number by returned by the function read_emp printf("%s",emp.postion); printf(" is %d:\n",emp.postion); break; case 2: emp=read_emp_salary();//to get the number by returned by the function read_emp printf("%s",emp.postion2); printf(" is : %f\n",emp2.postion2); break; case 3: emp=read_emp_age(); fflush(stdin); emp=read_emp_salary(); printf("%s",emp.postion); printf(" is : %d...",emp.postion); printf("%s",emp.postion2); printf(" is : %f\n",emp2.postion2); break; for(;;){ default:         puts("ERROR");} } return 0; } struct employee read_emp_age() {         struct employee emp;         puttingfunction();         scanf("%d",&emp.age);         return emp; } struct employee read_emp_salary() {         struct employee emp; puttingfunction(); scanf("%f",&emp.salary); return emp; } int main(void) {         struct employee emp;         print_emp_asker(emp);         return 0; }```
• 12-18-2008
tabstop
You still can't assign a value to an array, even if it's inside a struct. To copy a string, you still need to use strcpy.
• 12-18-2008
lolguy
oh i thought its possible since it return the hole structure ? so its possible only for it to return only int ?
• 12-18-2008
tabstop
This has nothing to do with returning anything. You cannot assign to an array, no matter of what kind.

Code:

```int anarray[10]; char anotherarray[20]; float morearrays[30]; anarray = 5; /* can't do this */ anotherarray = "bob"; /* or this */ morearrays = 1.5f; /* or this */```
There is nothing involving a structure in your problem, other than that your structure contains an array.
• 12-18-2008
lolguy
Quote:

Originally Posted by tabstop
This has nothing to do with returning anything. You cannot assign to an array, no matter of what kind.

Code:

```int anarray[10]; char anotherarray[20]; float morearrays[30]; anarray = 5; /* can't do this */ anotherarray = "bob"; /* or this */ morearrays = 1.5f; /* or this */```
There is nothing involving a structure in your problem, other than that your structure contains an array.

thanks alot,i used strcpy to copy the name.