[LC++]getopts

Robert Elsner roberte at matchmaker.com
Sat Aug 11 02:49:04 UTC 2001


man 3 getopt

int getopt( int argc, char * const argv [], const char *opstring )


int main( int argc, char **argv )
{
    char achar;

    while ((c = getopt(argc,argv,"hdr:")) != EOF)
    {
        switch (c)
        {
            case 'h':
                    display_help();
                    break;
            case 'd':
                    enable_debug();
                    break;
            case 'r':
                    retries = atoi(optarg);
                    break;
            default:
                    display_usage();
                    exit(1);
        }
    }
    return(0);
}

opstring defines the arguments that you will use.
The colon after a letter means that this arguments requires an argument.

More info read the manpage

Julien Patrick Claassen wrote:

> Hello all!
>   Does anyone of you know a good or quick guide to the getopts library? I
> would appriciate any help!
>   I also need some guide to do some user login stuff. Please could you
> tell me of any document or supply me with a short summary of basic
> functions.
>   Thanks a lot!
>   My kindest regards
>          Julien
>
> Julien Patrick Claassen
> jclaassen at gmx.de
> julien at c-lab.de
> http://www.geocities.com/jjs_home
>
> SBS C-LAB
> Fuerstenallee 11
> 33102 Paderborn
>
> Phone: (+49) 5251 60 6060
> Fax: (+49) 5251 60 6065
>
> www.c-lab.de
>
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List




More information about the tuxCPProgramming mailing list