title: getopt error handling for multiple comma separated values
body: <p>how to validate a string variable for multiple combinations of comma separated values received from command line for getopt?</p>
  <pre><code>       case 'a' :
                      flaga=1;
                      alg = optarg;
                      printf(&quot;you entered option -a \&quot;%s\&quot;\n&quot;, optarg);
  
                      if(strcmp(alg,&quot;lr&quot;) == 0 )
                         {
                           ....//valid
                         }
                      else if(strcmp(alg,&quot;lda&quot;) == 0 )
                         {
                           ....//valid
                         }
                      else if(strcmp(alg,&quot;knn&quot;) == 0 )
                         {
                            ...//valid
                         }
                       &quot;&quot;&quot;&quot;&quot;
                        &quot;&quot;&quot;&quot;
                      else
                        {
                         printf(&quot;wrong value entered for option -a \n&quot;);
                         exit();
                         }
  </code></pre>
  <p>option -a can accept these values : &quot;knn&quot;,&quot;lda&quot;,&quot;lr&quot;,&quot;kart&quot;,&quot;nb&quot;,&quot;svm&quot; .</p>
  <p>The above code handles errors perfectly if user passes only single value .</p>
  <p>But option -a can accept multiple values as comma separated ,</p>
  <pre><code>                    Eg :   -a knn,lr,lda
  </code></pre>
  <p>User can pass these values in any combination of any values !!</p>
  <pre><code>                    Eg :   -a knn,lr,lda
                      Eg :   -a knn,lda.lr
                      Eg :   -a lda,lr
                      
  </code></pre>
  <p>How to check if user has passed valid values for option -a ?</p>
  <p>The above code i have written is included in switch case and can handle if only single value for option -a is passed .</p>