将 fnmatch 与 char 指针一起使用

Using fnmatch with a char Pointer

数组 options 包含以下形式的元素:“-option=value”。

参数 needed_option 包含例如 "option"

char *function(char *options[], char *needed_option){
    for(//go over all possible options){
       if(fnmatch("-???=*", options[i], 0) == 0){ //<--- look here
           char *ret = extract_value_from_option(); 
           return ret;
        }
    }

}

问题:有没有一种方法可以像在 printf() 中那样用函数参数 needed_option 替换“???”,其中 char * 可以是通过使用 %s 包括在内?

准备 sprintf()

  char current[256];
  sprintf(current, "-%s=*", needed_option);
  //...
  if(fnmatch(current, options[i], 0) == 0){ //...