小编hay*_*lci的帖子

getopt不解析参数的可选参数

在C中,getopt_long不会解析命令行参数参数的可选参数.

当我运行程序时,无法识别可选参数,如下面的示例运行.

$ ./respond --praise John
Kudos to John
$ ./respond --blame John
You suck !
$ ./respond --blame
You suck !
Run Code Online (Sandbox Code Playgroud)

这是测试代码.

#include <stdio.h>
#include <getopt.h>

int main(int argc, char ** argv )
{
    int getopt_ret, option_index;
    static struct option long_options[] = {
               {"praise",  required_argument, 0, 'p'},
               {"blame",  optional_argument, 0, 'b'},
               {0, 0, 0, 0}       };
    while (1) {
        getopt_ret = getopt_long( argc, argv, "p:b::",
                                  long_options,  &option_index);
        if (getopt_ret == -1) break;

        switch(getopt_ret)
        {
            case 0: break;
            case 'p': …
Run Code Online (Sandbox Code Playgroud)

c arguments getopt getopt-long optional-arguments

43
推荐指数
2
解决办法
3万
查看次数

在linux内核模块中,如何获取已知路径的inode

在linux 内核模块中(即在内核空间中工作),我有一个文件路径.

可以使用哪些函数来获取该文件的inode.具体来说,我需要让"inode*"指向文件的inode.

linux inode linux-kernel

4
推荐指数
1
解决办法
5109
查看次数