I want to Receives an array, its size, and a pointer to a specific member in memory into a function. The function will check whether the pointer points to one of the members of the array.
If so, the function will print all the elements of the array that are before the sent address - not including the pointer itself. If not, the function will print an appropriate message.
This is what I tried to do and I have a lot of warnings. How can I fix that?
void printBeforeX(int* arr, int n, int* x);
int main(void)
{
int size = 11;
int offset = 0;
int arr[11] = { 4 ,8 ,6 ,2 ,1 ,3 ,5 ,7 ,8 ,9 ,5 };
printf("Please enter an offset to search in the array’s address domain");
scanf("%d", &offset);
getchar();
printBeforeX(arr, size, arr + offset);
getchar();
return 0;
}
void printBeforeX(int* arr, int n, int* x)
{
if (*x > n)
{
printf("Index %d is out of the array range",*x);
}
}
For example for the index 5 I'm expecting the output: : 4 8 6 2 1 and for 11 I'm expecting : false message.