Question: I created a function for this:

```
int SIGN_CHECKER (char* x)
{
    if(*x == '!')
    {
        return 1;
    } else if(*x == '?')
    {
        return 1;
    } else if(*x == '^')
    {
        return 1;
    } else if(*x == '&')
    {
        return 1;
    } else if(*x == '%')
    {
        return 1;
    } else
    {
        return 0;
    }
}

```

But as you can see, it's not that efficient. Does anybody know a better way?

Answer: 
The typical execution speed over memory use optimization is to create a simple look-up table.

```
#include <stdbool.h>

int sign_checker (char x)
{
  static const bool is_special [256] = 
  {
    ['!'] = true,
    ['?'] = true,
    ['^'] = true,
    ['&'] = true,
    ['%'] = true,
  };

  return is_special [(unsigned char)x];
}

```

x86 machine code is very efficient (gcc -O3):

```
SIGN_CHECKER:
        movsx   rdi, dil
        movzx   eax, BYTE PTR is_special.0[rdi]
        ret
is_special.0:
        .zero   33
        .byte   1
        .zero   3
        .byte   1
        .byte   1
        .zero   24
        .byte   1
        .zero   30
        .byte   1
        .zero   161

```
you can try using regular expression, something like this :

```
#include <regex.h>      
#include <stdio.h>  
#include <stdlib.h>
int check_pattern(char *string, char *pattern){
    regex_t regex;
    int res;

    // Compile regex
    res = regcomp(&regex, pattern, 0);

    // if there is error on compiling regex
    if (res)
        exit(1);

    // Execute regex
    res = regexec(&regex, string, 0, NULL, 0);
    if (!res) 
        return (1);
    else 
        return (0);

    // Free memory
    regfree(&regex);
}

```

know pass to the function the string and the special signs in regex pattern :

```
int main()
{
    // special signs are : "?*-"
    printf("%d\n", check_pattern("abc?d", "[?*-]"));
} 

```

read more about how to use regular expression in c from this [article](https://www.educative.io/edpresso/how-to-write-regular-expressions-in-c).