main arguments

This is a discussion on main arguments within the C Programming forums, part of the General Programming Boards category; hi! I have a problem with argv input parameter. I have 5 input parameters. But sometime I only need four ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    main arguments

    hi!

    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
    Location
    Ontario, Canada
    Posts
    2,718
    I'm assuming you're using a loop to access them:

    Code:
    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
    Posts
    6,231
    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, 12: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, 07:43 PM

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