構造体を作成し、パラメータとして渡されたデータをフィールドに入力する関数を書くのに問題があります。私はCが初めてなので、これは私にとって非常に挑戦的です。
名前、生年、開始年のフィールドを持つ「Employee」という構造体を作成しました。
typedef struct {
char* name;
int birthyear;
int startyear;
} Employee;
私が作成した関数では、不完全な型へのポインターの逆参照に関するエラーが発生し続けます。また、不完全なタイプの構造体 Employee への sizeof の無効な適用に対してエラーが発生します。
Employee* make_employee(char *name, int birthyear, int startyear) {
struct Employee* newemployee = (struct Employee*)malloc(sizeof(struct Employee));
newemployee->name = name;
newemployee->birthyear = birthyear;
newemployee->startyear = startyear;
return newemployee;
}
私は非常に単純な間違いを犯していると確信していますが、助けと説明をいただければ幸いです!