How can I use getOpt to determine if no options are given in C?
<p>I'm working on a simple program that supposed to change a string to all uppercase or all lowercase depending on the arguments. For example, if the executable's name is <code>change</code> :</p>
<blockquote>
<p>./change -u thiswillbeuppercase</p>
<p>THISWILLBEUPPERCASE</p>
<p>./change -l THISWILLBELOWERCASE</p>
<p>thiswillbelowercase</p>
</blockquote>
<p>The issue im having if that i cannot figure out how to perform the uppercase action by default, if no options are provided. For example, this is how i would like it to perform:</p>
<blockquote>
<p>./change thiswillbeuppercase</p>
<p>THISWILLBEUPPERCASE</p>
</blockquote>
<p>Here is what my main function looks like currently:</p>
<pre><code>int main(int argc, char *argv[]) {
int c;
while((c = getopt(argc,argv,&quot;u:s:l:&quot;)) != -1){
    char *str = optarg;
    if(c == '?'){
        c = optopt;
        printf(&quot;Illegal option %c\n&quot;,c);
    } else{
    
        switch(c){
            case 'u':
                strupper(str);
                break;
            case 'l':
                strlower(str);
                break;
            case 's':
                strswitch(str);
                break;
            default:
                strupper(str);
                break;
    
        }
    }

}
return 0;
</code></pre>
<p>}</p>
<p>I tried calling the strupper function in the default part of the switch statement but that doesn't seem to work. As of now the program does nothing when  provided with no options.</p>
<p>I search stackoverflow for similar questions and i found someone with the <a href="https://stackoverflow.com/questions/26592217/having-getopts-to-show-help-if-no-options-provided">same issue</a>, but their question is related to bash and not C.</p>
<p>If anyone has any advice i would really appreciate it. Thank you.</p>