Re: Using argv[1] in C program

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Jerry Davis
Date:  
To: plug-discuss
Subject: Re: Using argv[1] in C program
On Saturday 15 January 2005 11:36 pm, Steve Smith wrote:

Since usage could be done at any point, and instead of doing the same print
statement over and over, I put the usage print into a function that can be
called anywhere.

This is good programming practice.

Uhhh... notice my programming style ... which is different than Steve's
I have programmed this way for 30 years. Even though K&R put their braces on
the next line. K&R was/is THE definitive book for many years.

Jerry

---------------------------

#include <stdio.h>

void usage(void);

int main(int argc, char** argv) {
  if ( argc > 1 ) {
    if (isdigit(argv[1][0])) {
      usleep((unsigned long) atol(argv[1]));
      return(0);
    }
    if ((strcmp(argv[1],"--usage") == 0)) {
      usage();
      return(0);
    } else {
      printf("\nusleep: bad argument %s: unknown option\n",argv[1]);
      usage();
      return(-1);
    }
  }
  usage();
  return(-1);
}


void usage(void) {
printf("usage: usleep [--usage] [microseconds]\n");
}

-----------------

<snip for bandwidth>

--
Registered Linux User: 275424
Today's Fortune: Two is not equal to three, even for large values of two.
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss