Created
September 27, 2015 11:41
-
-
Save msikma/209629e67033040b5b89 to your computer and use it in GitHub Desktop.
Command line arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) | |
{ | |
int a, b, len, chr; | |
for (a = 1; a < argc; ++a) { | |
switch ((int)argv[a][0]) { | |
case '\\': | |
case '/': | |
case '-': | |
// Scan through the passed options. | |
len = strlen(argv[a]); | |
for (b = 1; b < len; ++b) { | |
chr = (int)argv[a][b]; | |
switch (chr) { | |
case '?': | |
case 'h': | |
case 'H': | |
printf("help is on the way.\n"); | |
break; | |
default: | |
printf("something else\n"); | |
break; | |
} | |
} | |
break; | |
default: | |
printf("string: %s\n", argv[a]); | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to abstract the first switch to a function, but that doesn't work... what am I doing wrong?