核心轉儲的錯誤,我知道這queston已被要求多次,但還是我無法算出這個段錯誤 - 在使用getopt的
#include<stdio.h>
#include<getopt.h>
int ch;
int queue_time=60;
int thread_num=4;
char *scheduling_algo="FCFS";
extern char *optarg;
int port=8080;
int debug_flag,h_flag,l_flag;
int main(int argc,char *argv[])
{
while ((ch = getopt(argc, argv, "dhlprtns")) != -1)
switch(ch)
{
case 'd':
debug_flag=atoi(optarg); /* print address in output */
break;
case 'h':
h_flag=atoi(optarg);
break;
case 'l':
l_flag=atoi(optarg);;
break;
case 'p':
port = atoi(optarg);
break;
case 'r':
printf("%s",optarg);
break;
case 't':
queue_time = atoi(optarg);
break;
case 'n':
thread_num = atoi(optarg);
break;
case 's':
scheduling_algo = optarg;
break;
default:
printf("nothing was passed");
}
printf("%d",queue_time);
printf("%d",debug_flag);
printf("%d",h_flag);
printf("%d",l_flag);
}
我使用下面的命令
執行我的計劃./a.out -d -h -l -t 55
我收到核心轉儲錯誤。我在google上閱讀了幾個例子,但仍然面臨這個問題。任何人都可以幫忙嗎?
非常感謝,手冊頁非常混亂。現在我得到了一個清晰的圖像。我只需要爲那些冒號的標誌使用optarg。 – user2934433