Last active
April 12, 2018 13:57
-
-
Save 2jiwon/d219ff9900786ebff577c0f6aab924ea to your computer and use it in GitHub Desktop.
Take arguments and output them as if '-e' & '-c' options.
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> | |
int | |
main (int argc, | |
char* argv[]) | |
{ | |
int num; | |
if (argc >= 1) | |
num = argc; | |
char* str[num]; | |
int idx_buf[num]; | |
int i; | |
for (i = 0; i < num; i++) | |
{ | |
str[i] = argv[i]; | |
idx_buf[i] = 0; | |
} | |
int count = 0; | |
i = 0; | |
while (num) | |
{ | |
int j = 0; | |
while (str[i] != '\0') | |
{ | |
if (str[i][j] == '-') | |
{ | |
j++; | |
if (str[i][j] == 'e') | |
{ | |
idx_buf[i] = 1; | |
i++; | |
break; | |
} | |
else if (str[i][j] == 'c') | |
{ | |
idx_buf[i] = 2; | |
i++; | |
count = atoi (str[i]); | |
break; | |
} | |
} | |
else | |
{ | |
idx_buf[i] = 3; | |
i++; | |
break; | |
} | |
} | |
num--; | |
} | |
i = 1; | |
while (idx_buf[i] != 0) | |
{ | |
int idx; | |
if (idx_buf[i] == 1) | |
{ | |
i++; | |
if (idx_buf[i] == 3) | |
{ | |
idx = i; | |
while (count) | |
{ | |
printf ("%d %s\n", count, str[idx]); | |
count--; | |
} | |
i++; | |
continue; | |
} | |
} | |
else | |
i++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment