getopt
This commit is contained in:
parent
b5b554bf31
commit
561a344f30
3 changed files with 68 additions and 0 deletions
15
getopt/getopt.c
Normal file
15
getopt/getopt.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "hf:o:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'h': puts("Help"); break;
|
||||
case 'f': printf("File: %s\n", optarg); break;
|
||||
case 'o': printf("Output: %s\n", optarg); break;
|
||||
default: fprintf(stderr, "Usage: %s [-h] [-f file] [-o output]\n", argv[0]); return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue