Command Line Arguements

This is a discussion on Command Line Arguements within the C Programming forums, part of the General Programming Boards category; I am trying to write a program which uses command line arguements and options. The part I am have trouble ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    11

    Question Command Line Arguements

    I am trying to write a program which uses command line arguements and options. The part I am have trouble with is arranging all the different combinations. For example the options are as follows: -c, -a, -t, -p, -cp, -ca, -ct, -ctp, -tca, -tcap, and etc... for every possible combination. Or you can have the options seperated like -c -a -t, etc. My problem is this. How should I write the code so that when an option is chosen such as -cta, it wouldnt matter if the user put in that of -atc. What I am thinking is that I should convert the characters to the hex or decimal format and the sum of them would be the same no matter what combination..but how would I do that? Or should I do it someother way? Please help... Thanks in advance!

    -Chris
    Last edited by scaven; 04-13-2003 at 04:19 PM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I haven't tried compiling this:
    Code:
    for( i = 1; i < argc; i++ ) {
        if( argv[i][0] == '-' ) {
            for( j = 1; j < strlen( argv[i] ); j++ ) {
                switch( argv[i][j] ) {
                    case 'a':
                        // Do something...
                        break;
                    case 'c':
                        // Do something...
                        break;
                    case 't':
                        // Do something...
                        break;
                    case 'p':
                        // Do something...
                        break;
                }
            }
        }
    }
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    11

    It works!

    Thank you so much for the quick replies. They both worked great. Thanks again for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Command line arguements in functions.
    By SlyMaelstrom in forum C++ Programming
    Replies: 4
    Last Post: 10-30-2005, 06:41 AM
  2. Comparing command line arguements to a string.
    By SlyMaelstrom in forum C++ Programming
    Replies: 14
    Last Post: 10-30-2005, 03:56 AM
  3. command line arguements
    By screamer903 in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:59 AM
  4. Arguements for gnome?
    By mart_man00 in forum Tech Board
    Replies: 12
    Last Post: 07-30-2003, 04:46 PM
  5. Working With Command Line Arguements
    By mart_man00 in forum C Programming
    Replies: 4
    Last Post: 08-03-2002, 04:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21