Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C编程-getopt_C_Getopt - Fatal编程技术网

C编程-getopt

C编程-getopt,c,getopt,C,Getopt,当我使用-f时,我得到了一个错误的分段错误,有什么想法吗? -f选项用于选择输入文件 struct list_names filenames; list_names_init(&filenames, "filenames"); optind = 1; while ((ch = getopt(argc, argv, ":hvf:")) != -1) //where getopt defined { switch (ch) { case

当我使用-f时,我得到了一个错误的分段错误,有什么想法吗? -f选项用于选择输入文件

  struct list_names filenames;
  list_names_init(&filenames, "filenames");

  optind = 1;
  while ((ch = getopt(argc, argv, ":hvf:")) != -1)  //where getopt defined
    {
      switch (ch) {
        case 'h':
                printf("usage: ./hake [-h] [-v] [-f file]\n-h           print help\n-v           verbose mode; enable extra printing; can be repeated\n");
                printf("-f file      input filename; default is hakefile or Hakefile");
          break;
        case 'v':
          verbose = 1;
          break;
        case 'f':
          f_flag++;
          list_names_append_from_file(&filenames, optarg);
       printf("Read_file%s\n",optarg);
       read_file(optarg);
          break;

如果不知道如何定义来自文件的列表名称,很难回答您的问题。但是,分段错误意味着您几乎肯定向函数传递了错误类型或数量的参数,或者弄乱了指针。我建议您在使用gcc和-Wall-Werror的情况下重新编译,看看编译器是否没有立即告诉您出了什么问题。

如果不知道列表名称是如何定义的,那么很难回答您的问题。但是,分段错误意味着您几乎肯定向函数传递了错误类型或数量的参数,或者弄乱了指针。我建议重新编译,假设您正在使用带-Wall-Werror的gcc,看看编译器是否没有立即告诉您出了什么问题。

问题可能出在list\u names\u append\u from\u file方法中。问题可能出在list\u names\u append\u from\u file方法中。查看我的代码,你说得对,我给函数传递了错误数量的参数。我一直在研究如何将两个文件同时传递给一个列表,有可能吗?看看我的代码,你说的对,我传递给函数的参数数目不对。我一直在思考如何将两个文件同时传递给一个列表,有可能吗?