我试图通过在另一个数组中动态加倍来增加一个静态数组,一旦它达到最大值。我计划使用 malloc()
创建新数组,然后复制值。完成后,我计划删除第一个数组,然后将第一个指针指向第二个?
float FirstArray[1];
if (first array is full) {
float *TempArray = (float*) malloc (sizeof (float) * counter);
for (loop) {
TempArray[i] = FirstArray[i];
}
//I'm not sure how to point the static array to the dynamic one
free(FirstArray);
*FirstArray = &TempArray;
//i get this error with line above
//assignment makes integer from pointer without a cast
}
最佳答案
也许您应该考虑 realloc
,因为这正是它存在的原因。
关于c - 如何更改动态调整大小的数组的指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9550680/