- Your
lookuptable[]
has a space after "string1" which is inconsistent with the other entries. I have a feeling you didn't want this. - Your
keyfromstring()
is incrementingsym
wrong (this causes a segfault). Replace with:
int keyfromstring(char *key)
{
int i;
for (i=0; i < NKEYS; i++) {
t_symstruct *sym = lookuptable + i;
if (strcmp(sym->key, key) == 0)
return sym->val;
}
return BADKEY;
}
OR
int keyfromstring(char *key)
{
int i;
for (i=0; i < NKEYS; i++) {
if (strcmp(lookuptable[i].key, key) == 0)
return lookuptable[i].val;
}
return BADKEY;
}
- Put your
printf("Case: nothing happen\n");
inside adefault
.