I'm new to C programming. I want to make a linked list, so I did, but it doesn't work. After I do that, I made it for a test, but still it gives an error.
malloc: error for object 0xa000000000000000: pointer being realloc'd was not allocated
set a breakpoint in malloc_error_break to debug
How can I reallocate this array?
void Allocate(int **arr,int totalNum, int subNum)
{
for(int n=0;n<(totalNum+1);n++)
{
arr[n] = (int*)realloc(arr[n],(size_t)((subNum+1)*sizeof(int)));
}
}
int main()
{
int totalNum = 20;
int subNum = 5;
int **arr;
arr = (int**)malloc((totalNum+1)*sizeof(int*));
Allocate(arr,totalNum, subNum);
for(int n=1;n<(totalNum+1);n++)
{
for(int s=1;s<(subNum+1);s++)
{
arr[n][s] = rand()%5;
cout<<"arr["<<n<<"]["<<s<<"]: "<<arr[n][s]<<endl;
}
}
}