#include #include #include #include #include #include "boom.h" /* * author: pikachu * date: 24 aug 2015 * last update: 2 jun 2017 * pledge: this is my own work, unless otherwise noted */ /* this is the solution */ /* globals go here */ int g_debug = 0 ; // global declaration; extern definition in header int g_verbose = 0 ; /* defines go here, in SHOUTY_CASE */ #define N_DEFAULT 10 #define USAGE_MESSAGE "usage: boom [-vuh] [-n num] " int main(int argc, char * argv[]) { int is_up = 0 ; int ch ; int n = N_DEFAULT ; int i ; // this goes here while ((ch = getopt(argc, argv, "n:vuh")) != -1) { switch(ch) { case 'n': n = atoi(optarg) ; break ; case 'v': g_verbose = 1 ; break ; case 'u': is_up = 1 ; break ; case 'h': default: printf("%s\n", USAGE_MESSAGE) ; return 0 ; } } argc -= optind; argv += optind; if ( argc>0 ) { printf("%s\n", USAGE_MESSAGE) ; return 0 ; } /* example of an assertion */ assert(n>0) ; /* example of g_verbose */ if (g_verbose) { printf("%s:%d: n=%d\n", __FILE__, __LINE__, n) ; } /* * do not int i here! ASCII C does not allow it * */ if ( is_up ) { for (i=0;i<=n;i++) { printf("%d\n",i) ; } } else { /* is down */ for (i=n;i>=0;i--) { printf("%d\n",i) ; } } printf("Boom!\n") ; return 0 ; }