我使用通過在主程序中的make_employee函數出返回的指針具有麻煩。分配一個指針到一個結構到可變
//我有一個單獨的.c文件下面的代碼:
struct Employee;
struct Employee* make_employee(char* name, int birth_year, int start_year){
struct Employee* new = (struct Employee*)malloc(sizeof(struct Employee));
strcpy(new->name, name);
new->birth_year = birth_year;
new->start_year = start_year;
return new;
}
//In the main program:
int main()
{
char test_name[] = "Fred";
int test_birth = 1989;
int test_start = 2007;
Employee Fred;
make_employee(test_name, test_birth, test_start) = &Fred; <-- throws invalid lvalue error
return 0
}
即賦值語句的左側是.... *不*左值。或者在錯誤消息中不清楚。 – WhozCraig