zoukankan      html  css  js  c++  java
  • Linux C getopt_long

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

    char *l_opt_arg;
    char* const short_options = "c:";


    struct option long_options[] = {
      { "aa", 0, NULL, 0 },
      { "bb", 0, NULL, 0 },
      { "cc", required_argument, NULL, 'c' },
      { 0, 0, 0, 0},
    };


    int main(int argc, char *argv[])
    {
            int c;
            int index = 0;
            while((c = getopt_long (argc, argv, short_options, long_options, &index)) != -1)
            {
                    switch (c)
                    {
                            case 0:
                                    switch (index)
                                    {
                                            case 0:
                                                    printf("is aa : c = %d, index = %d ", c, index);
                                                    break;
                                            case 1:
                                                    printf("is bb : c = %d, index = %d ", c, index);
                                                    break;
                                            default:
                                                    printf("no one : c= %d, index = %d ", c, index);

                                                    break;

                                      }
                break;
            case 'c':
                l_opt_arg = optarg;
                printf("cc is %s(optarg), c = %c, index = %d! ", l_opt_arg, c, index);
                break;
          }
      }
      return 0;
    }

  • 相关阅读:
    jQuery 中 children() 与 find() 用法的区别
    JSON.parse()和JSON.stringify() 的用法区别
    Cookie 与Session 的区别(转载)
    Ajax的post方法,模拟 从后台读取数据小demo
    Tab切换栏
    C# Linq to Entity 多条件 OR查询
    C# 执行DOS命令和批处理
    C# 将DataTable数据源转换成实体类
    MYSQL 企业常用架构与调优经验分享
    C# 虚方法virtual详解
  • 原文地址:https://www.cnblogs.com/banwhui/p/4597318.html
Copyright © 2011-2022 走看看