Thread: command-line arguments or parameters to a program

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    94

    Unhappy command-line arguments or parameters to a program

    if I have a command-line argument such as:
    ./KR<alice.txt -x -n course

    and if my main function is:
    main(int argc, char *argv[])

    how many arguments (argc) I have?

    I need some support...

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    You can always try printing the value of argc if you're unsure. In this case, the "<" character will most likely (depending on your shell) redirect the contents of alice.txt to stdin.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    I would guess your shell would consume everything to the right of < in processing the redirection (maybe, I didn't try it).

    The usual convention would be
    ./KR -x -n course < alice.txt
    That is command line options precede filenames and redirections.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. a program that will call an execute but with arguments
    By what3v3r in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2006, 09:44 PM
  3. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  4. process parameters
    By gvector1 in forum C# Programming
    Replies: 3
    Last Post: 06-05-2003, 11:40 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM