简体   繁体   English

将fnmatch与char指针一起使用

[英]Using fnmatch with a char Pointer

The array options contains elements of this form: "-option=value". 数组options包含以下形式的元素:“-option = value”。

The argument needed_option contains for example "option" 参数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;
        }
    }

}

Question: Is there a way to genericly replace the " ??? " with the function - argument needed_option like its done in printf() where a char * can be included by using the %s ? 问题:有没有一种方法可以像needed_optionprintf()中那样用function-argument_option参数替换“ ??? ”,其中可以使用%s包含char *

prepare it with sprintf() sprintf()准备它

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM