multiple command line arguments

This is a discussion on multiple command line arguments within the C Programming forums, part of the General Programming Boards category; I am having a problem with using a switch statement and argv[] I need to create an interface that can ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    3

    Talking multiple command line arguments

    I am having a problem with using a switch statement and argv[]

    I need to create an interface that can be run as follows:

    program -w4f4 file1 file2.
    the argv[0], argv[2], and argv[3] are simple. Its the reading each character independently in argv[1] that is giving me the problem.

    I dont want to create a 2 page main with lots of options, I would prefer to do something that reads in the first character and then compares the next one.

    Any suggestions?

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Do you have any code?

    I would just check argv[1][0], then argv[1][1], and so on.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    The arguments on the command line can be treated as strings.

    argv [0] -> first string, name of program
    argv [1] -> second string, first argument
    argv [2] -> third string, second argument
    etc.

    You can then access the individual characters of the string like ygfperson explained. Or use the strcmp() or other string compare function to compare the strings.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Try this

    Also, if your compiler has it, use the non-standard function getopt().
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    3

    Smile THANKS ALL

    THANKS EVERYONE FOR YOUR HELP. I FINALLY FINISHED IT.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple command line arguments with switches
    By Ene Dene in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2009, 03:28 AM
  2. Sending multiple arguments to function..
    By Zzaacchh in forum C++ Programming
    Replies: 3
    Last Post: 09-06-2008, 04:20 PM
  3. Multiple arguments in the "if" command
    By |Wiz| in forum C++ Programming
    Replies: 11
    Last Post: 09-28-2005, 01:01 PM
  4. Phantom redefinition
    By CodeMonkey in forum C++ Programming
    Replies: 6
    Last Post: 06-12-2005, 06:42 PM
  5. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 03:41 AM

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