这是一项家庭作业,因此我不想发布任何代码,但是我对自己的错误感到很困惑.
This is a homework assignment so I don't want to post any code, but I'm pretty stumped with the bug that I have.
目前,我已经分配了一个数组,并且正在将指针复制到该数组.现在,我可以对该数组进行memcpy和memmove,并且工作正常.
Currently I have a array that has been malloced and am copying the pointer to the array. Now, I can memcpy and memmove with this array and that works fine.
但是,当我使用它进行重新分配时,出现了无效的指针错误-我完全不知道为什么.
However, when I do a realloc with it an invalid pointer error comes up - and I have absolutely no idea why.
任何人都可以帮忙吗?
Can anyone help?
推荐答案您说过我将指向此数组的指针复制到另一个变量中".问题是一旦执行重新分配,原始指针将不再有效.我看不到将指针复制到变量的原因吗?
you said 'I copy the pointer to this array into another variable'. The problem is as soon as you do a realloc, the original pointer is no longer valid. I dont see the reason to copy the pointer to a variable?
更多推荐
在C中重新分配无效的指针
发布评论