| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
24 バイト追加 、 2020年2月15日 (土) 08:01
編集の要約なし
getopt を利用することで、option指定方法のguidelineを簡単に実現できる。
独自の値をとるoption、取らないoptionの両方をsupportする。
#include <&lt;unistd.h>&gt;
int getopt(int argc, char *const argv[], const char *optstring);
extern char *optarg;
*optionが値をとる場合、外部変数 optargに値がセットされる
#include <&lt;unistd.h>&gt; #include <&lt;stdio.h>&gt;
extern char *optarg;extern int optind, opterr, optopt;
int i = 1; char c;
char os[3] = {'\0',':','\0'};
for( c = 'a'; c <&lt;= 'z'; c++) {
os[0] = c;
int opt = getopt(argc, argv, (const char*)&os);
if (opt > &gt; -1) {
printf("[%d]%c : %s\n", (i++), opt, optarg);
}

案内メニュー