Thread: bus error on empty argv when trying to print help message with -h

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    10

    bus error on empty argv when trying to print help message with -h

    I'm trying to get my program to print a simple help message if people use the '-h' switch on the command line. My code is:

    Code:
    	/* print help message if -h */
    	if (strcmp(argv[1], "-h") == 0) {
    
                 print a help message...	
    
    		exit(0);
    	}
    This works fine. However, when I run it with no switches (normal operation), I get a bus error.
    Any suggestions?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    check the argc value before accessing argv[1]
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    10

    solved

    Thanks, vart. That solved it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  2. Character arrays in a Structure
    By vsriharsha in forum C Programming
    Replies: 7
    Last Post: 07-11-2004, 05:36 PM
  3. Message printing problem
    By robert_sun in forum C Programming
    Replies: 1
    Last Post: 05-18-2004, 05:05 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM