getopt question

This is a discussion on getopt question within the C Programming forums, part of the General Programming Boards category; if I want to specify that the user must specify -p x, then is the following code valid? is there ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    getopt question

    if I want to specify that the user must specify -p x, then is the following code valid?
    is there a way to do that using the getopt? in other words if they don't specify it then an error occurs...
    or do I need to do that manually

    Code:
    getopt(argc, argv, "w:h:t:p:")
    Last edited by -EquinoX-; 03-26-2009 at 06:34 PM.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by -EquinoX- View Post
    if I want to specify that the user must specify -p x, then is the following code valid?
    is there a way to do that using the getopt? in other words if they don't specify it then an error occurs...
    or do I need to do that manually

    Code:
    getopt(argc, argv, "w:h:t:p:")
    Not sure what you mean by manually but getopt() won't enforce the "-p" option. You have to programatically determine if "-p" has been given on the cmd line and exit if not.

  3. #3
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    you should check up on getopt() I think fifth down the list might be what you're looking for.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so doing:

    Code:
    getopt(argc, argv, "w::h::t::p:" )
    is the same as saying that -w -h and -t are optional but -p are required?

    however when I do that it gives me a seg fault
    Last edited by -EquinoX-; 03-26-2009 at 08:42 PM.

  5. #5
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by -EquinoX- View Post
    so doing:

    getopt(argc, argv, "w::h::t::" )

    is the same as saying that -w -h and -t are optional but -p are required?

    however when I do that it gives me a seg fault

    well i'd take out the smiley face for starters then i'd try taking out that extra semi-colon.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    that smiley is not on purpose...it's gone now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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