Thread: Setting up a usage message cmd

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    1

    Setting up a usage message cmd

    Hi, I'm new to C programming and I'm currently working on an assignment that takes in cmd arguments and processes them.

    My issue is providing a customized usage message. Do i just type:
    usage:
    //my message

    and then its automatically saved?
    How do I then call that usage message to be printed when a user enters -help in cmd

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Oh, you mean something like this?
    Code:
    mycmd -h
    mycmd --help
    You have to make your program output the message you want when the user gives "-h" or "--help" through the command line. There are independent programs that display helpful information, such as "man" for linux.

    The simpler implementation for what you want, albeit ad-hoc, is something like the following:
    Code:
    // Inside a loop
    if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
        puts("Helpful message!");
    }
    Last edited by GReaper; 10-07-2017 at 05:50 PM.
    Devoted my life to programming...

  3. #3
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Code:
    void usage(void)
    {
      printf("Usage:\n"
                "Syntax is: [command1 <arg1..>] [command2 <arg1..>]...\n"
                "Accepts --long and -short options as --long options\n"
                "some stuff here \n"
                "Some more stuff here\n"
                "even more stuff here\n"
            
    
                "\n");
    }
    saves from writing printf more than once.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VC++ 6 - CPU Usage Help
    By solem1 in forum C Programming
    Replies: 0
    Last Post: 09-08-2009, 11:16 PM
  2. CPU usage
    By sandy143 in forum C Programming
    Replies: 3
    Last Post: 07-13-2007, 07:16 AM
  3. anyone help me on usage of this
    By black in forum C++ Programming
    Replies: 8
    Last Post: 05-24-2004, 08:25 PM
  4. 99% CPU Usage...
    By napkin111 in forum Game Programming
    Replies: 27
    Last Post: 03-04-2003, 11:37 AM
  5. Replies: 4
    Last Post: 01-06-2002, 06:22 PM

Tags for this Thread