{"id":89,"date":"2010-04-17T22:05:13","date_gmt":"2010-04-18T07:05:13","guid":{"rendered":"\/blog\/?p=89"},"modified":"2023-09-21T09:41:17","modified_gmt":"2023-09-21T00:41:17","slug":"getoptgetopt_long","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=89","title":{"rendered":"getopt(),getopt_long()"},"content":{"rendered":"\n<P>\uc774\ubc88\uc5d0\ub294 getopt \ud568\uc218\ub97c \uc5b4\ub5bb\uac8c \ud638\ucd9c\ud558\ub294\uc9c0\uc5d0 \ub300\ud574\uc11c \uc790\uc138\ud788 \uc124\uba85\ud55c\ub2e4. \uc774 \uae30\ub2a5\uc744 \uc0ac\uc6a9\ud558\uae30 \uc704\ud574\uc11c,<br \/>\ub2f9\uc2e0\uc758 \ud504\ub85c\uadf8\ub7a8\uc5d0 \ud5e4\ub354\ud30c\uc77c `unistd.h'\uc744 \ud3ec\ud568\uc2dc\ucf1c\uc57c\ub9cc \ud55c\ub2e4.<br \/>\ubcc0\uc218 : &nbsp; int opterr<br \/>\ub9cc\uc77c \uc774 \ubcc0\uc218\uc758 \uac12\uc774 0\uc774 \uc544\ub2c8\uba74, getopt\ub294 \ub9cc\uc77c \uc54c\uc9c0\ubabb\ud558\ub294 \uc635\uc158 \ubb38\uc790\uac00 \ub4e4\uc5b4\uc624\uac70\ub098 \uc778\uc218\ub97c \ud544\uc694\ub85c<br \/>\ud558\ub294 \uc635\uc158\uc774 \uc635\uc158\uc744 \uac16\uace0\uc788\uc9c0 \uc54a\ub2e4\uba74 \ud45c\uc900 \uc5d0\ub7ec \uc2a4\ud2b8\ub9bc\uc5d0 \uc5d0\ub7ec\uba54\uc138\uc9c0\ub97c \ud504\ub9b0\ud2b8\ud55c\ub2e4. \uc774\uac83\uc740 \ub514\ud3f4\ud2b8<br \/>\ub3d9\uc791\uc774\ub2e4.&nbsp; \ub9cc\uc77c \ub2f9\uc2e0\uc774 \uc774 \ubcc0\uc218\ub97c 0\uc73c\ub85c \uc124\uc815\ud558\uba74, getopt\ub294 \uc544\ubb34\ub7f0 \uba54\uc2dc\uc9c0\ub3c4 \ud504\ub9b0\ud2b8\ud558\uc9c0\ub294 \uc54a\uc9c0\ub9cc,<br \/>\uc5d0\ub7ec\ub97c \uc9c0\uc801\ud558\uae30 \uc704\ud574\uc11c \uc5ec\uc804\ud788 ? \ubb38\uc790\ub97c \uc5ec\uc804\ud788 \ub9ac\ud134\ud55c\ub2e4.<br \/>\ubcc0\uc218 : &nbsp; int optopt<br \/>getopt\uac00 \uc54c\ub824\uc9c0\uc9c0 \uc54a\uc740 \uc635\uc158 \ubb38\uc790\uc640 \ub9cc\ub098\uac70\ub098 \ud544\uc694\ud55c \uc778\uc218\uac00 \ube60\uc838\uc788\ub294 \uc635\uc158\uc77c \ub54c, getopt\ub294 \uadf8 \uc635\uc158<br \/>\ubb38\uc790\ub97c \uc774 \ubcc0\uc218\uc5d0 \uc800\uc7a5\ud55c\ub2e4.&nbsp; \ub2f9\uc2e0\uc740 \uc790\uc2e0\ub9cc\uc758 \uc9c4\ub2e8 \uba54\uc2dc\uc9c0\ub97c \uc81c\uacf5\ud558\uae30 \uc774\ud574\uc11c \uc774 \ubcc0\uc218\ub97c \uc0ac\uc6a9\ud560 \uc218<br \/>\uc788\ub2e4.<br \/>\ubcc0\uc218 : &nbsp; int optind<br \/>\uc774 \ubcc0\uc218\ub294 \uc55e\uc73c\ub85c \ubd84\uc11d\ud560 \ubc30\uc5f4 argv\uc758 \ub2e4\uc74c \uc694\uc18c\uc5d0 \ub300\ud55c \uc778\ub371\uc2a4\ub85c getopt\uc5d0 \uc758\ud574 \uc124\uc815\ub41c\ub2e4.&nbsp; \uc77c\ub2e8<br \/>getopt\uac00 \uc635\uc158 \uc778\uc218\ub4e4 \ubaa8\ub450\ub97c \ubc1c\uacac\ud588\ub2e4\uba74, \ub2f9\uc2e0\uc740 \ub098\uba38\uc9c0 \ube44-\uc635\uc158 \uc778\uc218\ub4e4\uc774 \uc5b4\ub514\uc5d0\uc11c \uc2dc\uc791\ud558\ub294\uc9c0 \uacb0<br \/>\uc815\ud558\uae30 \uc704\ud574\uc11c \uc774 \ubcc0\uc218\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.&nbsp; \uc774 \ubcc0\uc218\uc758 \ucd08\uae30\uac12\uc740 1\uc774\ub2e4.<br \/>\ubcc0\uc218 : &nbsp; chat *optarg<br \/>\uc774 \ubcc0\uc218\ub294 \uc778\uc218\ub4e4\uc744 \ubc1b\uc544\ub4e4\uc774\ub294 \uc635\uc158\ub4e4\uc744 \uc704\ud574\uc11c, \uc635\uc158 \uc778\uc218\ub4e4\uc758 \uac12\uc744 \uac00\ub9ac\ud0a4\ub294 \ud3ec\uc778\ud130\ub85c\uc368 getopt<br \/>\uc5d0 \uc758\ud574 \uc124\uc815\ub41c\ub2e4.<\/P>\n<P>\ud568\uc218 : &nbsp; int getopt(int argc, char **argv, const char *options)<br \/>getopt \ud568\uc218\ub294 argv\uc640 argc \uc778\uc218\ub4e4\uc5d0\uc758\ud574 \uc9c0\uc815\ub41c \uc778\uc218 \ubaa9\ub85d\uc73c\ub85c\ubd80\ud130 \ub2e4\uc74c \uc635\uc158 \uc778\uc218\ub97c \uc5bb\ub294\ub2e4.&nbsp; \ubcf4<br \/>\ud1b5, \uadf8\ub4e4 \uac12\ub4e4\uc740 main\uc5d0 \uc758\ud574 \ubc1b\uc544 \ub4e4\uc5ec\uc9c4 \uc778\uc218\ub4e4\ub85c\ubd80\ud130 \uc9c1\uc811\uc801\uc73c\ub85c \uc628\ub2e4.&nbsp; \uc635\uc158 \uc778\uc218\ub294 \uc774 \ud504\ub85c\uadf8<br \/>\ub7a8\uc5d0\uc11c \uc720\uc6a9\ud558\uac8c \uc4f0\uc77c \uc635\uc158 \ubb38\uc790\ub4e4\uc744 \uc9c0\uc815\ud55c \ubb38\uc790\uc5f4\uc774\ub2e4.&nbsp; \ubb38\uc790\uc5f4\uc548\uc5d0 \uc788\ub294 \uc635\uc158 \ubb38\uc790\ub294 \uc778\uc218\uac00 \ud544<br \/>\uc694\ud568\uc744 \uc54c\ub9ac\uae30 \uc704\ud574\uc11c \ucf5c\ub860(`:')\uc758 \ub2e4\uc74c\uc5d0 \ub098\ud0c0\ub09c\ub2e4.<br \/>\ub9cc\uc77c \uc635\uc158 \uc778\uc218 \ubb38\uc790\uc5f4\uc774 \ud558\uc774\ud508(`-')\uc73c\ub85c \uc2dc\uc791\ud55c\ub2e4\uba74, \uc774\uac83\uc740 \ud2b9\ubcc4\ud558\uac8c \ucde8\uae09\ub41c\ub2e4.&nbsp; \uadf8\ub4e4\uc740 \uc635\uc158 \ubb38<br \/>\uc790\uac00 `\\0'\uc778\uac83\ucc98\ub7fc \ub9ac\ud134\ub418\uc5b4, \uc635\uc158\uc774 \uc5c6\ub294 \uc778\uc218\ub4e4\uc744 \ud5c8\uc6a9\ud55c\ub2e4.&nbsp; getopt \ud568\uc218\ub294 \ub2e4\uc74c \ucee4\ub9e8\ub4dc \ub77c\uc778\uc635\uc158<br \/>\uc758 \uc635\uc158 \ubb38\uc790\ub97c \ub9ac\ud134\ud55c\ub2e4.&nbsp; \ub354 \uc774\uc0c1 \uc720\uc6a9\ud55c \uc635\uc158 \uc778\uc218\ub4e4\uc774 \uc5c6\uc744 \ub54c, -1\uc744 \ub9ac\ud134\ud55c\ub2e4.&nbsp; \uadf8\uacf3\uc740 \uc774\uc81c \ube44<br \/>-\uc635\uc158 \uc778\uc218\ub4e4\uc774 \uc788\uc744 \uac83\uc774\ub2e4; \ub2f9\uc2e0\uc740 \uc774\uac83\uc744 \uccb4\ud06c\ud558\uae30 \uc704\ud574\uc11c argc \ud30c\ub77c\ubbf8\ud130\uc5d0 \ub300\uc751\ud558\ub294<br \/>\uc678\ubd80\ubcc0\uc218 optind\ub97c \ube44\uad50\ud574\uc57c\ub9cc \ud55c\ub2e4.<br \/>\ub9cc\uc77c \uc5b4\ub5a4 \uc635\uc158\uc774 \uc778\uc218\ub97c \uac00\uc9c4\ub2e4\uba74, getopt \ub294 \ubcc0\uc218\ub4e4 optarg\uc548\uc5d0 \uadf8\uac83\uc744 \uc800\uc7a5\ud568\uc73c\ub85c\uc368 \uc778\uc218\ub97c \ub9ac\ud134<br \/>\ud55c\ub2e4.&nbsp; \ub2f9\uc2e0\uc774 \ub367\uc50c\uc6cc\uc9c8\uc9c0\ub3c4 \ubaa8\ub974\ub294 \uc815\uc801 \ubcc0\uc218\uac00 \uc544\ub2cc, \ubcf4\ud1b5\uc758 argv \ubc30\uc5f4\uc744 \uac00\ub9ac\ud0a4\ub294 \ud3ec\uc778\ud130\ub97c \ub77c\uba74,<br \/>optarg \ubb38\uc790\uc5f4\uc744 \ubcf5\uc0ac\ud560 \ud544\uc694\uac00 \uc5c6\ub2e4.<br \/>\ub9cc\uc77c \uc54c\ub824\uc9c0\uc9c0 \uc54a\uc740 \uc635\uc158\ubb38\uc790\ub97c \uc0ac\uc6a9\ud558\uac70\ub098, \uc635\uc158 \uc778\uc218\uac00 \ube60\uc838\uc788\ub2e4\uba74 getopt\ub294 `?'\ub97c \ub9ac\ud134\ud558\uace0 \ud604\uc7ac<br \/>\uc635\uc158 \ubb38\uc790\ub85c \uc678\ubd80\ubcc0\uc218 optopt\ub97c \uc124\uc815\ud55c\ub2e4.&nbsp; \ub9cc\uc77c \uc635\uc158\uc758 \uccab \ubc88\uc9f8 \ubb38\uc790\uac00 \ucf5c\ub860(`:') \uc774\ub77c\uba74, getopt\ub294<br \/>\uc635\uc158 \uc778\uc218\uac00 \ube60\uc838\uc788\uc74c\uc744 \uc54c\ub9ac\uae30 \uc704\ud574\uc11c `?' \ub300\uc2e0\uc5d0 `:'\ub97c \ub9ac\ud134\ud55c\ub2e4. \ub610\ud55c, \ub9cc\uc77c \uc678\ubd80\ubcc0\uc218 opterr\uc774 0<br \/>\uc774 \uc544\ub2c8\uba74(\ub514\ud3f4\ud2b8\uc774\ub2e4.), getopt\ub294 \uc5d0\ub7ec \uba54\uc2dc\uc9c0\ub97c \ucd9c\ub825\ud55c\ub2e4.<br \/>22.1.3&nbsp; getopt\ub97c \uc0ac\uc6a9\ud574\uc11c \uc778\uc218\ub97c \uad6c\ubb38\ubd84\uc11d\ud558\ub294 \uc608\uc81c.<br \/>&nbsp;\ub2e4\uc74c\uc740 getopt\uac00 \uc804\ud615\uc801\uc73c\ub85c \uc5b4\ub5bb\uac8c \uc0ac\uc6a9\ub418\ub294\uc9c0\ub97c \ubcf4\uc5ec\uc8fc\ub294 \uc608\uc81c\uc774\ub2e4. \ud575\uc2ec\uc740 \ub2e4\uc74c\uacfc \uac19\ub2e4:<br \/>\ub441 \ubcf4\ud1b5, getopt\ub294 \ub8e8\ud504\uc548\uc5d0\uc11c \ud638\ucd9c\ub41c\ub2e4.&nbsp; getopt\uac00 \ub354 \uc774\uc0c1 \ub098\ud0c0\ub09c \uc635\uc158\uc774 \uc5c6\uc74c\uc744 \uc54c\ub9ac\uae30 \uc704\ud574\uc11c -1<br \/>\uc744 \ub9ac\ud134\ud558\uba74, \ub8e8\ud504\ub294 \uc885\ub8cc\ud55c\ub2e4.<br \/>\ub441 switch \uad6c\ubb38\uc740 getopt\ub85c\ubd80\ud130\uc758 \ub9ac\ud134\uac12\uc5d0 \ub530\ub978 \uac01\uac01\uc758 \ucc98\ub9ac\uc5d0 \uc0ac\uc6a9\ub41c\ub2e4. \uac01\uac01\uc758 \uacbd\uc6b0\ub294 \ud504\ub85c\uadf8\ub7a8\uc5d0<br \/>\uc11c \ub098\uc911\uc5d0 \uc0ac\uc6a9\ub420 \ubcc0\uc218\ub97c \uc124\uc815\ud558\uac8c \ub41c\ub2e4.<br \/>\ub441 \ub450 \ubc88\uc9f8 \ub8e8\ud504\ub294 \ub0a8\uc544\uc788\ub294 \ube44-\uc635\uc158 \uc778\uc218\ub4e4\uc744 \ucc98\ub9ac\ud558\ub294\ub370 \uc0ac\uc6a9\ub41c\ub2e4.<br \/>&nbsp; #include&nbsp; &lt;unistd.h&gt;<br \/>&nbsp; #include&nbsp; &lt;stdio.h&gt;<br \/>&nbsp; int<br \/>&nbsp; main&nbsp; (int&nbsp; argc,&nbsp; char&nbsp; **argv)<br \/>&nbsp; {<br \/>&nbsp; &nbsp;&nbsp; int&nbsp; aflag&nbsp; =&nbsp; 0;<br \/>&nbsp; &nbsp;&nbsp; int&nbsp; bflag&nbsp; =&nbsp; 0;<br \/>&nbsp; &nbsp;&nbsp; char&nbsp; *cvalue&nbsp; =&nbsp; NULL;<br \/>&nbsp; &nbsp;&nbsp; int&nbsp; index;<br \/>&nbsp; &nbsp;&nbsp; int&nbsp; c;<br \/>&nbsp; &nbsp;&nbsp; opterr&nbsp; =&nbsp; 0;<br \/>&nbsp; &nbsp;&nbsp; while&nbsp; ((c&nbsp; =&nbsp; getopt&nbsp; (argc,&nbsp; argv,&nbsp; \"abc:\"))&nbsp; !=&nbsp; -1)<br \/>&nbsp; &nbsp; &nbsp;&nbsp; switch&nbsp; (c)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 'a':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aflag&nbsp; =&nbsp; 1;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; case&nbsp; 'b':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bflag&nbsp; =&nbsp; 1;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 'c':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cvalue&nbsp; =&nbsp; optarg;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; '?':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&nbsp; (isprint&nbsp; (optopt))<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; fprintf(stderr, \"Unknown option `-%c'.\\n\", optopt);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; fprintf&nbsp; (stderr,<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; \"Unknown option character `\\\\x%x'.\\n\", optopt);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return&nbsp; 1;<br \/>&nbsp; &nbsp; &nbsp; default:<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; abort&nbsp; ();<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp;&nbsp; printf(\"aflag = %d, bflag = %d, cvalue = %s\\n\", aflag, bflag, cvalue);<br \/>&nbsp; &nbsp;&nbsp; for&nbsp; (index&nbsp; =&nbsp; optind;&nbsp; index&nbsp; &lt;&nbsp; argc;&nbsp; index++)<br \/>&nbsp; &nbsp; &nbsp;&nbsp; printf&nbsp; (\"Non-option&nbsp; argument&nbsp; %s\\n\",&nbsp; argv[index]);<br \/>&nbsp; &nbsp;&nbsp; return&nbsp; 0;<br \/>&nbsp; }<br \/>&nbsp;\ub2e4\uc74c\uc740 \uc704\uc758 \ud504\ub85c\uadf8\ub7a8\uc744 \uc5ec\ub7ec \uac00\uc9c0 \uc778\uc218\ub4e4\uc758 \uc870\ud569\uc744 \uc0ac\uc6a9\ud588\uc744 \ub54c \uc5b4\ub5a4 \uacb0\uacfc\ub97c \ub098\ud0c0\ub0b4\ub294\uc9c0\uc5d0 \ub300\ud55c<br \/>\uc608\uc774\ub2e4.<br \/>%&nbsp; testopt<br \/>aflag&nbsp; =&nbsp; 0,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>%&nbsp; testopt&nbsp; -a&nbsp; -b<br \/>aflag&nbsp; =&nbsp; 1,&nbsp; bflag&nbsp; =&nbsp; 1,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>%&nbsp; testopt&nbsp; -ab<br \/>aflag&nbsp; =&nbsp; 1,&nbsp; bflag&nbsp; =&nbsp; 1,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>%&nbsp; testopt&nbsp; -c&nbsp; foo<br \/>aflag&nbsp; =&nbsp; 0,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; foo<br \/>%&nbsp; testopt&nbsp; -cfoo<br \/>aflag&nbsp; =&nbsp; 0,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; foo<br \/>%&nbsp; testopt&nbsp; arg1<br \/>aflag&nbsp; =&nbsp; 0,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>Non-option&nbsp; argument&nbsp; arg1<br \/>%&nbsp; testopt&nbsp; -a&nbsp; arg1<br \/>aflag&nbsp; =&nbsp; 1,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>Non-option&nbsp; argument&nbsp; arg1<br \/>%&nbsp; testopt&nbsp; -c&nbsp; foo&nbsp; arg1<br \/>aflag&nbsp; =&nbsp; 0,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; foo<br \/>Non-option&nbsp; argument&nbsp; arg1<br \/>%&nbsp; testopt&nbsp; -a&nbsp; --&nbsp; -b<br \/>aflag&nbsp; =&nbsp; 1,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>Non-option&nbsp; argument&nbsp; -b<br \/>%&nbsp; testopt&nbsp; -a&nbsp; -<br \/>aflag&nbsp; =&nbsp; 1,&nbsp; bflag&nbsp; =&nbsp; 0,&nbsp; cvalue&nbsp; =&nbsp; (null)<br \/>Non-option&nbsp; argument&nbsp; -<\/P>\n<P>&nbsp;<\/P>\n<P>&nbsp;<\/P>\n<P>22.1.4&nbsp; \uae34 \uc635\uc158\ub4e4\uc744 \uad6c\ubb38\ubd84\uc11d\ud558\uae30.<\/P>\n<P><br \/>&nbsp;\ub2e8\uc77c\ud55c-\ubb38\uc790 \uc635\uc158\ub4e4\ub85c\ub9cc \ub418\uc5b4\uc788\ub294 GNU-\uc2a4\ud0c0\uc77c\uc758 \uae34 \uc635\uc158\ub4e4\uc744 \ubc1b\uc544\ub4e4\uc774\uae30 \uc704\ud574\uc11c\ub294 getopt \ub300\uc2e0\uc5d0<br \/>getopt_long\ub97c \uc0ac\uc6a9\ud55c\ub2e4.&nbsp; \ub2f9\uc2e0\uc740 \uc774\ub7f0 \uac00\uc678\uc758 \uc791\uc740 \uc791\uc5c5\uc744 \ud1b5\ud574\uc11c \ubaa8\ub4e0 \ud504\ub85c\uadf8\ub7a8\uc774 \uae34 \uc635\uc158\ub4e4\uc744 \ubc1b<br \/>\uc544\ub4e4\uc774\uac8c \ub9cc\ub4e4 \uc218 \uc788\uace0, \ucd08\ubcf4\uc790\ub4e4\uc5d0\uac8c \uc5b4\ub5bb\uac8c \uadf8 \ud504\ub85c\uadf8\ub7a8\uc744 \uc0ac\uc6a9\ud558\ub294\uc9c0 \ub3c4\uc6b8 \uc218\uc788\ub2e4.<br \/>\ub370\uc774\ud130 \ud0c0\uc785 : &nbsp; struct option<br \/>\uc774 \uad6c\uc870\uccb4\ub294 getopt_long\uc744 \uc704\ud55c \ub2e8\uc77c\ud55c \uae34 \uc635\uc158 \uc774\ub984\uc744 \uc124\uba85\ud55c\ub2e4. \uae34 \uc635\uc158\uc744 \uad6c\uc131\ud558\ub294 \uc635\uc158\uc758 \ud558\ub098<br \/>\uc778 \uc778\uc218 longopts\ub294 \uadf8\ub4e4 \uad6c\uc870\uccb4\uc758 \ubc30\uc5f4\uc774 \ub418\uc5b4\uc57c\ub9cc \ud55c\ub2e4.&nbsp; \uadf8 \ubc30\uc5f4\uc740 0\uc73c\ub85c \ucc44\uc6cc\uc9c4 \uc694\uc18c\ub85c\uc368 \ub05d\ub09c<br \/>\ub2e4. struct option \uad6c\uc870\uccb4\ub294 \ub2e4\uc74c\uacfc \uac19\uc740 \ud544\ub4dc\ub97c \uac16\ub294\ub2e4.<br \/>const char *name<br \/>\uc774 \ud544\ub4dc\ub294 \uc635\uc158\uc758 \uc774\ub984\uc73c\ub85c \ubb38\uc790\uc5f4\uc774\ub2e4.<br \/>int has_arg<br \/>\uc774 \ud544\ub4dc\ub294 \uc635\uc158\uc774 \uc778\uc218\ub97c \ucde8\ud558\ub294\uc9c0 \ub610\ub294 \ucde8\ud558\uc9c0 \uc54a\ub294\uc9c0\uc758 \uc5ec\ubd80\ub97c \uc54c\ub9b0\ub2e4.&nbsp; \uadf8\uac83\uc740 \uc815\uc218\uc774\uace0 \uadf8\uacf3\uc5d0<br \/>\uc138 \uac1c\uc758 \ud569\ub9ac\uc801\uc778 \uac12\ub4e4\uc774 \uc788\ub2e4: no_argument, required argument, \uadf8\ub9ac\uace0 optional_argument<br \/>int *flag<br \/>int val<br \/>\uc774 \ud544\ub4dc\ub4e4\uc740 \uadf8 \uc635\uc158\uc774 \ubc1c\uc0dd\ud560 \ub54c \uc635\uc158\uc5d0 \ub300\ud558\uc5ec \uc5b4\ub5bb\uac8c \ubcf4\uace0\ub97c \ud558\uac70\ub098 \ub3d9\uc791\ud560\uac83\uc778\uc9c0\ub97c \uc81c\uc5b4\ud55c\ub2e4.<br \/>\ub9cc\uc77c flag\uac00 \ub110 \ud3ec\uc778\ud130\ub77c\uba74, val\uc740 \uc774 \uc635\uc158\uc744 \ub300\ud45c\ud558\ub294 \uac12\uc774\ub2e4.&nbsp; \uc885\uc885 \uadf8 \uac12\ub4e4\uc740 \ud2b9\uc815\ud55c \uae34 \uc635\uc158\ub4e4\uc758<br \/>\ub2e8\uc77c\ud568\uc744 \ud655\uc778\ud558\uae30 \uc704\ud574\uc11c \uc120\ud0dd\ub418\uc5b4\uc9c4\ub2e4.&nbsp; \ub9cc\uc77c \ud50c\ub798\uadf8\uac00 \ub110 \ud3ec\uc778\ud130\uac00 \uc544\ub2c8\ub77c\uba74, \uadf8\uac83\uc740 \uc774 \uc635\uc158\uc744<br \/>\uc704\ud55c \ud50c\ub798\uadf8\uc778 int\ud615 \ubcc0\uc218\uc758 \uc8fc\uc18c\uac00 \ub418\uc5b4\uc9c8 \uac83\uc774\ub2e4. val\uc548\uc758 \uac12\uc740 \ub098\ud0c0\ub09c \uc635\uc158\uc744 \uc9c0\uc801\ud558\ub3c4\ub85d \ud50c\ub798\uadf8<br \/>\uc548\uc5d0 \uc800\uc7a5\ud558\uae30 \uc704\ud55c \uac12\uc774\ub2e4.<\/P>\n<P><br \/>\ud568\uc218 :<br \/>int getopt__long (int argc, char **argv, const char *shortopts, struct<br \/>option *longopts, int *indexptr)<\/P>\n<P><br \/>&nbsp;\ubca1\ud130 argv ( \uae38\uc774\ub294 argc\uc774\ub2e4.)\ub85c\ubd80\ud130 \uc635\uc158\ub4e4\uc744 \ud574\ub3c5\ud55c\ub2e4.&nbsp; \uc778\uc218 shortopts\ub294 getopt\uac00 \ud574\ub3c5\ud560 \uc218 \uc788<br \/>\ub294 \ub9cc\ud07c\uc758 \uc9e7\uc740 \uc635\uc158\uc744 \ub098\ud0c0\ub0b4\uace0, \uc778\uc218 longopts\ub294 \ubc1b\uc544\ub4e4\uc774\uae30 \uc704\ud55c \uae34 \uc635\uc158\ub4e4\uc744 \ub098\ud0c0\ub0b8\ub2e4.<br \/>getopt_long\uc774 \uc9e7\uc740 \uc635\uc158\uc744 \ub9cc\ub0ac\uc744 \ub54c, \uadf8\uac83\uc740 getopt\uac00 \ud558\ub294\uac83\uacfc \uac19\uc740 \uc77c\uc744 \ud55c\ub2e4: \uadf8\uac83\uc740 \uc635\uc158\uc744 \uc704<br \/>\ud55c \ubb38\uc790 \ucf54\ub4dc\ub97c \ub9ac\ud134\ud558\uace0, optarg\uc5d0 \uc635\uc158 \uc778\uc218\ub4e4\uc744(\ub9cc\uc77c \uadf8\uac83\uc774\ud55c \uac1c\ub97c \uac00\uc9c4\ub2e4\uba74) \uc800\uc7a5\ud55c\ub2e4.<br \/>getopt_long\uac00 \uae34 \uc635\uc158\uc744 \ub9cc\ub0ac\uc744 \ub54c, \uadf8\uac83\uc740 \uadf8 \uc635\uc158\uc744 \uc815\uc758\ud558\ub294 flag \uc640 val \ud544\ub4dc\uc5d0 \uae30\ucd08\ud55c \ub3d9\uc791\ub4e4<br \/>\uc744 \ucde8\ud55c\ub2e4.<br \/>\ub9cc\uc77c flag\uac00 \ub110 \ud3ec\uc778\ud130\ub77c\uba74, getopt_long \uc740 \ubc1c\uacac\ud55c \uc635\uc158\uc744 \uc9c0\uc801\ud558\ub3c4\ub85d val\uc758 \ub0b4\uc6a9\uc744 \ub9ac\ud134\ud55c\ub2e4.&nbsp; \ub2f9\uc2e0<br \/>\uc774 \ub2e4\ub978 \uc758\ubbf8\ub97c \uac00\uc9c4 \uc635\uc158\uc744 \uc704\ud574\uc11c val \ud544\ub4dc\uc548\uc5d0 \ubcc4\uac1c\uc758 \uac12\ub4e4\uc744 \ubc30\uc5f4\ud558\uba74, \ub2f9\uc2e0\uc740 getopt_long\uc774 \ub9ac<br \/>\ud134\ud55c \ud6c4\uc5d0 \uadf8\ub4e4 \uac12\uc744 \ud574\ub3c5\ud560 \uc218 \uc788\ub2e4.&nbsp; \ub9cc\uc77c \uae34 \uc635\uc158\uc774 \uc9e7\uc740 \uc635\uc158\uacfc \ub3d9\uc77c\ud558\ub2e4\uba74, \ub2f9\uc2e0\uc740 \uc9ed\uc740 \uc635\uc158\uc758<br \/>\ubb38\uc790 \ucf54\ub4dc\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<br \/>\ub9cc\uc77c flag\uac00 \ub110 \ud3ec\uc778\ud130\uac00 \uc544\ub2c8\ub77c\uba74, \ub2e8\uc9c0 \ud504\ub85c\uadf8\ub7a8\uc548\uc5d0\uc11c flag\uac00 \uc124\uc815\ub41c \uc774 \uc635\uc158\uc744 \uc758\ubbf8\ud55c\ub2e4.&nbsp; flag\ub294<br \/>\ub2f9\uc2e0\uc774 \uc815\uc758\ud55c int\ud615\uc758 \ubcc0\uc218\uc774\ub2e4.&nbsp; flag \ud544\ub4dc\uc548\uc5d0 \uadf8 \ud50c\ub798\uadf8\uc758 \uc8fc\uc18c\ub97c \uc800\uc7a5\ud558\ub77c.&nbsp; flag\uc5d0 \uc800\uc7a5\ud558\ub824\ub294<br \/>\uc635\uc158\uac12\uc744 val \ud544\ub4dc\uc548\uc5d0 \uc800\uc7a5\ud558\ub77c.&nbsp; \uc774 \uacbd\uc6b0, getopt_long\ub2940\uc744 \ub9ac\ud134\ud55c\ub2e4.<br \/>\uc5b4\ub5a4 \uae34 \uc635\uc158\uc5d0\uc11c, getopt_long\ub294 \ubc30\uc5f4 longopts\uc548\uc758 \uc635\uc158 \uc815\uc758\uc5d0 \ub300\ud55c \uc778\ub371\uc2a4\ub97c, *indexptr\uc5d0 \uc800\uc7a5\ud558<br \/>\uc5ec \uc54c\ub9b0\ub2e4.&nbsp; \ub2f9\uc2e0\uc740 longopts[*indexptr].name \uc73c\ub85c \uc635\uc158\uc758 \uc774\ub984\uc744 \uc5bb\uc744 \uc218 \uc788\ub2e4. \uadf8\ub798\uc11c \ub2f9\uc2e0\uc740 \uadf8\ub4e4<br \/>\uc758 val \ud544\ub4dc\uc548\uc5d0 \uc788\ub294 \uac12\uc774\ub098, \uadf8\ub4e4\uc758 \uc778\ub371\uc2a4\uc5d0 \uc758\ud574\uc11c \uae34 \uc635\uc158\ub4e4\uc744 \uad6c\ubd84\ud560 \uc218 \uc788\ub2e4.&nbsp; \ub2f9\uc2e0\uc740 \ud50c\ub798\uadf8<br \/>\ub97c \uc124\uc815\ud55c \uae34 \uc635\uc158\ub4e4\uc744 \uc774 \ubc29\ubc95\uc73c\ub85c \uad6c\ubd84\ud560 \uc218 \uc788\ub2e4.<br \/>\uc5b4\ub5a4 \uae34 \uc635\uc158\uc774 \uc778\uc218\ub97c \uac00\uc9c8 \ub54c, getopt_long\ub294 \ub9ac\ud134\ud558\uae30 \uc804\uc5d0 \ubcc0\uc218 optarg\uc548\uc5d0 \uc778\uc218\uac12\uc744 \uc800\uc7a5\ud55c\ub2e4.<br \/>\uc5b4\ub5a4 \uc635\uc158\uc774 \uc544\ubb34\ub7f0 \uc778\uc218\ub97c \uac00\uc9c0\uc9c0 \uc54a\uc744 \ub54c, optarg\uc548\uc758 \uac12\uc740 \ub110 \ud3ec\uc778\ud130\uc774\ub2e4.&nbsp; \uc774\uac83\uc740 \uacf5\uae09\ub41c\uc778\uc218\uac00<br \/>\uc635\uc158\uc744 \uac00\uc84c\ub294\uc9c0 \uc544\ub2cc\uc9c0\uc5d0 \ub300\ud55c \uc5ec\ubd80\ub97c \ub2f9\uc2e0\uc5d0\uac8c \uc54c\ub9ac\ub294 \ubc29\ubc95\uc778 \uac83\uc774\ub2e4.&nbsp; getopt_long\ub294 \ub354 \uc774\uc0c1 \ucc98<br \/>\ub9ac\ud560 \uc635\uc158\ub4e4\uc774 \uc5c6\uc744 \ub54c, -1\uc744 \ub9ac\ud134\ud558\uace0, \ub2e4\uc74c \ub0a8\uc544\uc788\ub294 \uc778\uc218\uc758 argv \uc778\ub371\uc2a4\ub97c \ubcc0\uc218 optind \uc548\uc5d0 \ub0a8\uae34<br \/>\ub2e4.<br \/>22.1.5&nbsp; \uae34 \uc635\uc158\ub4e4\uc758 \uad6c\ubd84\ubd84\uc11d\uc5d0 \ub300\ud55c \uc608\uc81c.<br \/>&nbsp;&nbsp; #include&nbsp; &lt;stdio.h&gt;<br \/>\/*&nbsp; \ud50c\ub798\uadf8\ub294 `--verbose' \uc5d0 \uc758\ud574 \uc124\uc815\ud55c\ub2e4. *\/<br \/>&nbsp; &nbsp; &nbsp; static&nbsp; int&nbsp; verbose_flag;<br \/>&nbsp; &nbsp; &nbsp; int<br \/>&nbsp; &nbsp; &nbsp; main&nbsp; (argc,&nbsp; argv)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; int&nbsp; argc;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; char&nbsp; **argv;<br \/>&nbsp; &nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; int&nbsp; c;<br \/>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; while&nbsp; (1)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; static&nbsp; struct&nbsp; option&nbsp; long_options[]&nbsp; =<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br \/>\/*&nbsp; \uadf8\ub4e4 \uc635\uc158\ub4e4\uc740 \ud50c\ub798\uadf8\ub97c \uc124\uc815\ud55c\ub2e4.*\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"verbose\",&nbsp; 0,&nbsp; &amp;verbose_flag,&nbsp; 1},<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"brief\",&nbsp; 0,&nbsp; &amp;verbose_flag,&nbsp; 0},<br \/>\/* \uadf8\ub4e4 \uc635\uc158\ub4e4\uc740 \ud50c\ub798\uadf8\ub97c \uc124\uc815\ud558\uc9c0 \uc54a\ub294\ub2e4. \uc6b0\ub9ac\ub294 \uadf8\ub4e4\uc758 \uc778\ub371\uc2a4\uc5d0 \uc758\ud574 \uadf8\ub4e4\uc744 \uad6c\ubd84\ud55c\ub2e4. *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"add\",&nbsp; 1,&nbsp; 0,&nbsp; 0},<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"append\",&nbsp; 0,&nbsp; 0,&nbsp; 0},<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"delete\",&nbsp; 1,&nbsp; 0,&nbsp; 0},<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"create\",&nbsp; 0,&nbsp; 0,&nbsp; 0},<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {\"file\",&nbsp; 1,&nbsp; 0,&nbsp; 0},<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {0,&nbsp; 0,&nbsp; 0,&nbsp; 0}<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };<br \/>\/* getopt_long\ub294 \uc774\uacf3\uc5d0 \uc635\uc158 \uc778\ub371\uc2a4\ub97c \uc800\uc7a5\ud55c\ub2e4. *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int&nbsp; option_index&nbsp; =&nbsp; 0;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c&nbsp; =&nbsp; getopt_long&nbsp; (argc,&nbsp; argv,&nbsp; \"abc:d:\", long_options,&nbsp; &amp;option_index);<br \/>\/* \uc635\uc158\ub4e4\uc758 \ub05d\uc744 \uac80\ucd9c\ud55c\ub2e4.&nbsp; *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&nbsp; (c&nbsp; ==&nbsp; -1)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch&nbsp; (c)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 0:<br \/>\/* \ub9cc\uc77c \uc774 \uc635\uc158\uc774 \ud50c\ub798\uadf8\ub97c \uc124\uc815\ud558\uba74, \uc9c0\uae08 \uc544\ubb34\ub7f0 \uc77c\ub3c4 \ud558\uc9c0 \ub9d0\uc544\ub77c.&nbsp; *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; if&nbsp; (long_options[option_index].flag&nbsp; !=&nbsp; 0)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; printf(\"option %s\", long_options[option_index].name);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; if (optarg)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; printf(\"&nbsp; with&nbsp; arg&nbsp; %s\",&nbsp; optarg);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; printf(\"\\n\");<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 'a':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; puts(\"option&nbsp; -a\\n\");<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 'b':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; puts(\"option&nbsp; -b\\n\");<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 'c':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; printf(\"option&nbsp; -c&nbsp; with&nbsp; value&nbsp; `%s'\\n\",&nbsp; optarg);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; 'd':<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; printf(\"option&nbsp; -d&nbsp; with&nbsp; value&nbsp; `%s'\\n\",&nbsp; optarg);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case&nbsp; '?':<br \/>\/* getopt_long\ub294 \uc774\ubbf8 \uc5d0\ub7ec \uba54\uc2dc\uc9c0\ub97c \ud504\ub9b0\ud2b8\ud588\ub2e4. *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; break;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; abort&nbsp; ();<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; }<br \/>\/* \uadf8\ub4e4\uc774 \ub9de\ucd94\ucce4\ub358 \uac83\uc73c\ub85c `--verbose'\uc640 `--brief'\ub97c \ubcf4\uace0\ud558\ub294 \ub300\uc2e0\uc5d0, \uc6b0\ub9ac\ub294 \uadf8\ub4e4\ub85c\ubd80\ud130 \ub098\uc628 \uacb0<br \/>\uacfc\ub85c \ub9c8\uc9c0\ub9c9 \uc0c1\ud669\uc744 \ubcf4\uace0\ud55c\ub2e4.&nbsp; *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; if&nbsp; (verbose_flag)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; puts&nbsp; (\"verbose&nbsp; flag&nbsp; is&nbsp; set\");<br \/>\/* \ub0a8\uc544\uc788\ub294 \ucf54\ub9e8\ub4dc \ub77c\uc778 \uc778\uc218\ub4e4\uc744( \uc635\uc158\uc774 \uc5c6\ub294) \ucd9c\ub825\ud558\ub77c. *\/<br \/>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; if&nbsp; (optind&nbsp; &lt;&nbsp; argc)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf&nbsp; (\"non-option&nbsp; ARGV-elements:&nbsp; \");<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while&nbsp; (optind&nbsp; &lt;&nbsp; argc)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf&nbsp; (\"%s&nbsp; \",&nbsp; argv[optind++]);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putchar&nbsp; ('\\n');<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; exit&nbsp; (0);<br \/>&nbsp; &nbsp; &nbsp; }<br \/>\n","protected":false},"excerpt":{"rendered":"<p>\uc774\ubc88\uc5d0\ub294 getopt \ud568\uc218\ub97c \uc5b4\ub5bb\uac8c \ud638\ucd9c\ud558\ub294\uc9c0\uc5d0 \ub300\ud574\uc11c \uc790\uc138\ud788 \uc124\uba85\ud55c\ub2e4. \uc774 \uae30\ub2a5\uc744 \uc0ac\uc6a9\ud558\uae30 \uc704\ud574\uc11c,\ub2f9\uc2e0\uc758 \ud504\ub85c\uadf8\ub7a8\uc5d0 \ud5e4\ub354\ud30c\uc77c `unistd.h&#8217;\uc744 \ud3ec\ud568\uc2dc\ucf1c\uc57c\ub9cc \ud55c\ub2e4.\ubcc0\uc218 : &nbsp; int opterr\ub9cc\uc77c \uc774 \ubcc0\uc218\uc758 \uac12\uc774 0\uc774 \uc544\ub2c8\uba74, getopt\ub294 \ub9cc\uc77c \uc54c\uc9c0\ubabb\ud558\ub294 \uc635\uc158 \ubb38\uc790\uac00 \ub4e4\uc5b4\uc624\uac70\ub098 \uc778\uc218\ub97c \ud544\uc694\ub85c\ud558\ub294 \uc635\uc158\uc774 \uc635\uc158\uc744 \uac16\uace0\uc788\uc9c0 \uc54a\ub2e4\uba74 \ud45c\uc900 \uc5d0\ub7ec \uc2a4\ud2b8\ub9bc\uc5d0 \uc5d0\ub7ec\uba54\uc138\uc9c0\ub97c \ud504\ub9b0\ud2b8\ud55c\ub2e4. \uc774\uac83\uc740 \ub514\ud3f4\ud2b8\ub3d9\uc791\uc774\ub2e4.&nbsp; \ub9cc\uc77c \ub2f9\uc2e0\uc774 \uc774 \ubcc0\uc218\ub97c 0\uc73c\ub85c \uc124\uc815\ud558\uba74, getopt\ub294 \uc544\ubb34\ub7f0 \uba54\uc2dc\uc9c0\ub3c4 \ud504\ub9b0\ud2b8\ud558\uc9c0\ub294 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[22],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-development_unix"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}