簡體   English   中英

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

}

問題:有沒有一種方法可以像needed_optionprintf()中那樣用function-argument_option參數替換“ ??? ”,其中可以使用%s包含char *

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