command-line arguments or parameters to a program

This is a discussion on command-line arguments or parameters to a program within the C Programming forums, part of the General Programming Boards category; if I have a command-line argument such as: ./KR<alice.txt -x -n course and if my main function is: main(int argc, ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06: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, 08: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

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