Searching an array with pointers
So I think I am finally getting the hang of pointers. I even made a simple program to swap values of pointers through a function. I know, simple, but it was just a way of making sure I knew what I was doing. I am still having trouble with pointers and arrays though.
Take a look at this problem:
Write the following function:
int search (int a [], int n, int key);
a in an array to be searched, n is the number of elements in the array, and key is the search key. search should return 1 if key matches some element of a, 0 if it doesn’t.
Suppose you have an array of 10 numbers with the following values: 10, 20, 13, 32, 50, 25, 40, 49, 11, 12. Use the search function you made earlier to print out whether the values 10, 145, 15, and 11 exist in the array. Write this section in main.
Now then.. The signature of the function must remain the same, and I am getting stuck.
The only thing I have so far is this:
Code:
#include <stdio.h>
#include <stdlib.h>
int search (int a [], int n, int key){
int b;
for(b=0; b<=n; n++){
/*search for values with pointer*/
}
int main()
{
int array[]={10, 20, 13, 32, 50, 25, 40, 49, 11, 12};
search(array[]); /*run function with values*/
system("PAUSE");
return 0;
}