2014年11月13日 星期四

[C] How to make option





    /* Skip the executable name and start with the arguments. */
index
= 1;

/* Parse all the options. */
while (index < argc)
{
if (strcmp(argv[index], "-H") == 0)
{
index
= index + 2;
}
else if (strcmp(argv[index], "-plugin") == 0)
{
print_usage
();
index
= index + 1;
}
else
{
/* This could be a plugin specific option. */

}
}

Usage :

binfile -n          <-- index = index + 1;
binfile
-n happy <-- index = index + 2;

Related Posts:

0 意見:

張貼留言