這就是我想要做的事:誤差函數返回一個結構
我一直在努力,我已創建一個結構(在主硬編碼)代碼,然後我想爲兩個結構的malloc空間(試着使用功能)。然後將第一個結構中的所有數據複製到第二個結構並打印新結構。
發生的錯誤是: 我不明白這個錯誤的含義。
pointer.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
pointer.c:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
#include <stdio.h>
#include <stdlib.h>
#include "pointer.h"
int rec = 0;
線7
struct emp *create(int record){
emp *new_employees = malloc(sizeof(info) * (record+1));
return new_employees;
}
線13
struct emp *copy(emp *data, int record){
emp *new_employee = create(record+1);
int i;
for(i = 0; i<record;i++){
new_employee.first = data.first;
new_employee.last = data.last;
new_employee.start_date = data.start_date;
new_employess.sal = data.sal;
data++;
}
return new_employee;
}
int main(void){
struct info employees;
employees.first = "FIRST";
employees.last = "LAST";
employees.start_date = "June-20th-2006";
employees.sal = 55555.55;
rec = rec+1;
}
頭文件:
#include <string.h>
struct info {
char *first;
char *last;
char *start_date;
float sal;
} emp;
是的,但'信息'是類型,而不是'emp' – lkuty
@LudovicKuty是的,困惑它。我更新了答案,但它不會顯示爲編輯... – sidyll