I am learning the pointer and I stuck on an issue as I cannot debug the program because it gives me address rather than the actual array.
I am trying to create an Abstract datatype of Array
struct ARRAY_ADT
{
int *A; // For storing the pointer to base address of the array
int size; //For storing the size of the array
int len; //For storing the length of the array
};
Now to insert a number in it's correct index I had written a function called Insert. I am calling it from main.
It's look like this
void insert(struct ARRAY_ADT *Array)
{
int num;
int index;
int i = Array -> len - 1;
printf("Enter the value to be inserted: ");
scanf("%d", &num);
printf("Enter the value to be index: ");
scanf("%d", &index);
printf("Array length:%d \n", Array ->len);
if(OutofRange(Array -> size, Array -> len))
{
printf("Array is full:");
}
else
{
if (OutofRange(Array -> size, index))
{
printf("Index is not valid");
}
else
{
//int *temp = NULL;
while(i >= index)
{
Array->(A+i+1) = Array->(A+i); // Problem
i--;
}
Array -> A[index] = num;
Array -> len++;
}
}
}
So, how can I copy value from right to left to make place for the new number.
How can I copy value in a struct that is passed by reference to the function and member A is also a pointer?
I just want to perform this operation
Array.A[i++] = Array.A[i];