Using getopt
This commit is contained in:
parent
fb6226dd6b
commit
6731edbf57
1 changed files with 5 additions and 12 deletions
17
pwd.c
17
pwd.c
|
@ -6,19 +6,12 @@
|
|||
|
||||
int main(int argc, char * argv[]) {
|
||||
int mode = 01; /* 01: print PWD -L, 02: print physical path -P */
|
||||
char c;
|
||||
|
||||
if(argc > 1) {
|
||||
for(int i = 1; i < argc; i++) {
|
||||
if(argv[i][1] == 'L' && argv[i][2] == '\0') {
|
||||
mode = 01;
|
||||
}
|
||||
else if(argv[i][1] == 'P' && argv[i][2] == '\0') {
|
||||
mode = 02;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s: invalid option: %s\n", argv[0], argv[i]);
|
||||
exit(1);
|
||||
}
|
||||
while((c = getopt(argc, argv, "LP")) != -1) {
|
||||
switch(c) {
|
||||
case 'L': mode = 01; break;
|
||||
case 'P': mode = 02; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue