這是擴展結構數組的正確方法嗎?擴展結構數組
typedef struct { int x,y,z;} student_record;
int main(){
student_record data_record[30]; // create array of 30 student_records
num_of_new_records = 5;
data_record = realloc(data_record,(sizeof(data_record) + (sizeof(student_record)*num_of_new_records)));
// do I now have an array of 35 student_records???
那麼我應該使用什麼方法?創建一個更大的新臨時數組並複製,然後malloc()第一個到我想要的大小並再次複製回來? – 2012-03-13 21:54:54
如果你想使用'realloc()',不要使用數組。使用指針和'malloc()'。 – 2012-03-13 21:58:02