Thread: Taking inputs at Command Line

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    1

    Taking inputs at Command Line

    I have a problem. If my program is executed from the Command Prompt similar to:

    C:\some_directory\program.exe input1 input2

    How do I access the extra inputs? I've tried messing around with everything and the only output I can get is how many inputs are done.

    Code:
    int main (int argc){
    cout << argc
    }
    with C:\ some_directory\program.exe input1 input2 input3

    returns 3.

    Thanks in advance.
    Stephen.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Stephenf
    Code:
    int main (int argc){
    cout << argc
    }
    This is not a valid prototype for main.
    It should be
    Code:
    int main (int argc, char ** argv){
       for ( int i = 0; i < argc; ++i )
          cout << argv[i] << endl;
       return 0;
    }
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I validate these inputs?
    By Kyeong in forum C Programming
    Replies: 1
    Last Post: 10-19-2008, 02:20 PM
  2. checking inputs meets multiple conditions
    By 60beetle60 in forum C Programming
    Replies: 5
    Last Post: 04-19-2008, 08:25 AM
  3. I need help with validation for two inputs
    By KarrieWojo in forum C Programming
    Replies: 14
    Last Post: 12-20-2007, 11:55 AM
  4. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM
  5. Getting multiple inputs using cin
    By edk in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2001, 02:34 PM