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

This is a discussion on bus error on empty argv when trying to print help message with -h within the C Programming forums, part of the General Programming Boards category; I'm trying to get my program to print a simple help message if people use the '-h' switch on the ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    check the argc value before accessing argv[1]
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 05: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

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