0
當我使用-f得到錯誤分段錯誤時,有什麼想法? -f選項用於選擇輸入文件。C編程 - getopt
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;
可能不是問題出在你的'list_names_append_from_file'方法中。 – Kevin 2012-02-25 03:30:24