Skip to content

Instantly share code, notes, and snippets.

@levex
Created August 15, 2018 07:32
Show Gist options
  • Save levex/5168971a7772444967df746431ea384a to your computer and use it in GitHub Desktop.
Save levex/5168971a7772444967df746431ea384a to your computer and use it in GitHub Desktop.
Processing arguments in C
char *s;
while (--argc > 0 && (*++argv)[0] == '-')
for(s = argv[0]+1; *s != '\0'; s++)
switch(*s) {
case 'x':
/* Set appropriate flags for 'x' option */
break;
case 'n':
/* Set appropriate flags for 'n' option */
break;
default:
printf("Illegal option %c\n", *s);
argc = 0;
break;
}
if( argc != 1)
printf("Usage: find -x -n pattern\n");
else
/* Main program logic goes here */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment