I keep getting bad pointers. Can anyone tell me what am I doing wrong?
int SearchString( char* arr[], char* key, int size )
{
int n;
for ( n = 0; n < size; ++n ) {
if ( strcmp(arr[n], key) ) {
return n;
}
}
return -1;
}
char str[][16] = { "mov","cmp","add","sub","lea","not","clr","inc","dec","jmp","bne","red","jrn","psr","rts","stop"};
if(SearchString(str,"word",16) == -1){ return FALSE;}
Can’t tell where your
wordoriginates from. You probably want toif (!strcmp(arr[n],key)) return n;(the reverse). And the type of array is probably not what you want. Tryinstead. You have an array of arrays of characters and pass it where you actually expect an array of pointers.