Как я могу исправить ошибку на странице руководства? - PullRequest
0 голосов
/ 06 ноября 2018

Думаю, я мог найти ошибку на странице руководства и хотел бы узнать, как ее можно исправить в будущем. В данном случае речь идет о "man 3 getopt".
Приведен следующий пример:

   getopt()
   The following trivial example program uses getopt() to handle two program options: -n, with
   no associated value; and -t val, which expects an associated value.

   #include <unistd.h>
   #include <stdlib.h>
   #include <stdio.h>

   int
   main(int argc, char *argv[])
   {
       int flags, opt;
       int nsecs, tfnd;

       nsecs = 0;
       tfnd = 0;
       flags = 0;
       while ((opt = getopt(argc, argv, "nt:")) != -1) {
           switch (opt) {
           case 'n':
               flags = 1;
               break;
           case 't':
               nsecs = atoi(optarg);
               tfnd = 1;
               break;
           default: /* '?' */
               fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n",
                       argv[0]);
               exit(EXIT_FAILURE);
           }
       }

       printf("flags=%d; tfnd=%d; nsecs=%d; optind=%d\n",
               flags, tfnd, nsecs, optind);

       if (optind >= argc) {
           fprintf(stderr, "Expected argument after options\n");
           exit(EXIT_FAILURE);
       }

       printf("name argument = %s\n", argv[optind]);

       /* Other code omitted */

       exit(EXIT_SUCCESS);
   }

после цикла отсутствует оператор типа "optind -;"
в противном случае, по моему мнению, невозможно выполнить эту программу без сообщения об ошибке.

...