Thread: Command line parameters

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    1

    Command line parameters

    Ok so in my program I have developer mode, which just prints out info that I need for testing. You go into developer mode by putting a d after the program name. My problem is that if no command line parameters are input, the program gives a segmentation fault when run.

    How would you ignore the fact that there's no command line parameters? I guess I could trigger developer mode in a different way but this seems like a good idea.

    HELP PLZ

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Lemme guess. You are checking the value of argv[1], but of course argv[1] does not exist if there were no parameters.

    You should check the value of argc first to determine if there where parameters.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parameters quick Question
    By lifeis2evil in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2007, 11:12 PM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  3. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 11:46 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. command-line parameters.
    By Tombear in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 08:40 AM