**I have use this code to use switch case for a string** 

```
#define BADKEY -1
#define b 1
#define s 2
#define r 3
#define p 4

typedef struct { char *key; int val; } t_symstruct;

static t_symstruct lookuptable[] = {
{"b",b},{"s",s},{"r",r,{"p",p}
 };

#define NKEYS (sizeof(lookuptable)/sizeof(t_symstruct))

int main () {

```

**what is a mistake here?**

```
 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;
 }

```

**switch case in c**

```
switch (keyfromstring(field1))
{
     case b :
     printf(" is b\n" );
     break;

     case s :
     printf("is s\n" );
     break;

     case r :
     printf(" is r\n" );
     break;

     case ps:
     printf("is p\n" );
     break;

     case BADKEY:
     printf("Case: BADKEY \n");
     break;

     default://case if nothing
     printf("Case: nothing happen\n"); 
}

```

\*\*I got this message error segmentation fault(core dumped) 
after printing some lines correctly,so please what can be the error here?