Okay I have to write a program that accepts 2 or more arguments and searches the second and remaining arguments for a matching argument.
for example the output would be:
./a 3 h 4 9 3
3 found
or
./a hsi and iash me 34 hsi
hsi found
So far I have this, and I'm pretty sure I've got a lot of junk in here that is useless in the situation. Any help provided would be greatly appreciated!:
int linear_search (const char*A[], char*x, int v ){
int i;
i = 0;
while ( i < v - 1){
if (A[i] == x){
return 1;
}
return 0;
}
}
int main (int argc, char*argv[]){
int size = argc - 1;
char*A[size];
char*x = argv [1];
int i;
int v = argc - 2;
i = 0;
while ( i < v ){
A[i] = argv [i + 1];
i = i +1;
}
if (linear_search (A, v, x)){
printf ("%s found\n", x);
} else {
printf ("%s not found\n", x);
}
}
Whenever I run the program through the compiler I get the warning: passing arg 1 of 'linear_search' from incompatible pointer type.
warning: passing arg 2 of 'linear_search' makes pointer from integer without a cast.
What does that mean?