0
잘못된 옵션/명령을 입력해도 while 루프를 입력하지 않으면 프로그램이 기본 대소 문자를 사용합니다. 나는 내가 뭘 잘못하고 있는지 궁금 하네. 제대로 작동하기 위해서는 내가 바꿀 필요가있는 것이있다. 올바른 경우에만 사용된다. :) 의견에서C - getopt 스위치 while 루프와 잘못된 옵션의 기본 경우
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
int main (int argc, char *argv[]){
const char *optstring = "rs:pih";
char option;
while ((option = getopt(argc, argv, optstring)) != EOF) {
printf("I'm in the while loop!");
switch (option) {
case 'r':
break;
case 's':
printf("Second Argument: %s", optarg);
break;
case 'p':
printf("p");
break;
case 'i':
printf("i");
break;
case 'h':
printf("h");
break;
default:
printf("nothing");
}
}
return 0;
}
을 // www가 .gnu.org/software/libc/manual/html_node/Example-of-Getopt.html # Getopt 예제 –
나를 위해 완벽하게 잘 작동하는 것 같습니다. 테스트 케이스를 게시하십시오. – Dolda2000
나의 테스트 케이스는 ./program_name d – John