我試圖動態地爲一個結構內部的等級創建一個ints數組,但是我有一個小的語法錯誤。這裏是我的代碼:在一個結構內動態分配一個int數組
typedef struct
{
int Stud_ID;
int class_ID;
int* Grades;
int Grade_Cap;
int Count;
float Average;
}enrollment;
typedef struct
{
int Enrollment_Count;
int Enrollment_Cap;
enrollment *enrollment_list;
}enrollments;
void add_grade_space(enrollments *enroll)
{
enroll->enrollment_list[enroll->Enrollment_Count].Grade_Cap = malloc(sizeof(int)*2);
}
我得到的錯誤說:賦值使整數從指針沒有強制轉換。
成員'Grade_Cap'是一個'int'。你的意圖是什麼? – owacoder
您的意思是使用'....等級= malloc(sizeof(int)* 2;'? –
@RSahu也許是的,它肯定是一個錯字 – ameyCU