c - 如何更改动态调整大小的数组的指针?

标签 c

我试图通过在另一个数组中动态加倍来增加一个静态数组,一旦它达到最大值。我计划使用 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/

相关文章:

c - 体系结构 x86_64 : "_rb_funcallv" 的 undefined symbol

c++ - 为什么 gettimeofday() 间隔偶尔为负数?

c - 如何构建一个函数,将从文件(指针)获取的数据存储在结构中?

c - 使用 C 程序在窗口中查看图像?

在 C 中更改数据类型的名称

c - 是否有某种方法可以使 win32 GDI 调用以不同的方式解释坐标?

c - 错误 : expected identifier or ‘(’ before ‘=’ token

c++ - LoadLibrary 与将二进制 dll 加载到进程中?

c - C中的菱形数组排序

在 C 中将 float 转换为二进制数并显示