Thread: main arguments

  1. #1
    Code Warrior
    Join Date
    Nov 2001

    main arguments


    I have a problem with argv input parameter. I have 5 input parameters. But sometime I only need four of them (first, second, fourth and fifth). How can I exclude the third parameter?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    I'm assuming you're using a loop to access them:

    int a;
    for(a = 0; a < argc; a = ( ++a == 2 ? ++a : a ) ) {
    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
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Does your compiler have getopt() ? It's a useful function for accessing command line args. If you don't have it, you may be able to find the source on the web. (There are examples of its use on the forums here)

    Alternatively, check each command line options manually yourself. It's best to adopt an approach that means invoking your program something like this:

    >myprog.exe -aONE -bTWO -c

    then you can go:

    >myprog.exe -aONE -c
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too many arguments to function int main?
    By plain in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2006, 06:01 PM
  2. Actient main
    By swgh in forum C Programming
    Replies: 2
    Last Post: 03-21-2006, 01:33 PM
  3. C99 and int main()
    By cwr in forum C Programming
    Replies: 8
    Last Post: 09-19-2005, 06:54 AM
  4. Passing arguments to main?
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 10-16-2003, 03:59 AM
  5. arguments passed to main?!?
    By threahdead in forum C++ Programming
    Replies: 14
    Last Post: 01-22-2003, 08:43 PM