So I got an assignment in school that includes 3 strix (int ***) I need to write some int values into "pointers", but I get an error when I attempt to do so. Here's my code:
void main()
{
unsigned int size, i;
int arr[SIZE];
int ** pointers;
int ascend_flag;
printf("Please enter the number of items:\n");
scanf("%u", &size);
for (i = 0; i < size; i++)
scanf("%d", &arr[i]);
scanf("%d", &ascend_flag);
pointerSort(arr, size, (char)ascend_flag, &pointers);
printf("The sorted array:\n"); //Print the sorted array
printPointers(pointers, size);
free(pointers);
}
void pointerSort(int* arr, unsigned int size, char ascend_flag,
int *** pointers)
{
int i, j;
pointers = (int ***) malloc(size * sizeof(int **));
for (i = 0; i < size; i++)
{
***(pointers+i) = *&arr[i];
}
mergeSort(*pointers, size);
if (ascend_flag == 0)
{
for (i = 0, j = size - 1; i < (size / 2); i++, j--)
{
swapInArr(**(pointers + i), **(pointers + j));
}
}
}
The debugger shows that that the error occurs in this loop:
for (i = 0; i < size; i++)
{
***(pointers+i) = *&arr[i];
}
Specifically, I keep getting this error:
Exception thrown at 0x0127192A in Project3.exe: 0xC0000005: Access violation reading location 0xCDCDCDCD.
If there is a handler for this exception, the program may be safely continued
I acknowledge that the program is incomplete, and it may be flawed in ways unrelated to the error I'm getting. Please focus on issues related to the access violation error.