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;}
stris an array of 16 strings (the compiler created the 16 automatically) each of which can hold 15+1 characters (that you specified as the 2nd dimension). You may save a few bytes withchar str[][4] = {"mov", "cmp", ...};andif (SearchString(str, "word", sizeof str / sizeof *str) == -1) /* ... */;