[英]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_option
在printf()
中那樣用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.