commandlinec

commandlinec - break case 'v': v_option = true // print...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* File: commandline.c */ #include <stdio.h> #include <stdbool.h> #include <stdlib.h> int main(int argc, char *argv[]) { char *s, *cmd int a_option = false // default, no -a option int v_option = false // default, no -v option cmd = argv[0] if(argc == 1){ // no argument printf("Usage: %s [-av] names \n", cmd) exit(EXIT_FAILURE) } argc-- argv++ { /* empty space is not valid option */ for(s = argv[0]+1 *s!='\0' { switch(*s) { case 'a': a_option = true // get all possible matches
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: break case 'v': v_option = true // print message break default: printf(&quot;Warning: invalid option %c\n&quot;, *s) printf(&quot;Usage: %s [-av] names \n&quot;, cmd) break } } argc--argv++ } if(a_option) printf(&quot;option -a is on\n&quot;) if(v_option) printf(&quot;option -v is on\n&quot;) while(argc &gt; 0) { // print out the remaining arguments printf(&quot;%s\n&quot;, *argv) argc--argv++ } return 0 } Sheet1 Page 2 // for every argument beginning with -s++) // for -av...
View Full Document

Page1 / 2

commandlinec - break case 'v': v_option = true // print...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online