Last active
April 12, 2018 13:56
-
-
Save 2jiwon/aa611f59ac0cf827c48f5acaf19668ba to your computer and use it in GitHub Desktop.
Take arguments and output whether it contains hyphen or not, and so on...
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
/* Take arguments and output whether it contains hyphen or not. */ | |
#include <stdio.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; | |
} | |
i = 0; | |
while (num) | |
{ | |
int j; | |
for (j = 0; str[i] != '\0'; j++) | |
{ | |
if (str[i][j] == '-') | |
{ | |
idx_buf[i] = 1; | |
i++; | |
break; | |
} | |
else | |
{ | |
idx_buf[i] = 2; | |
i++; | |
break; | |
} | |
} | |
num--; | |
} | |
for (i = 0; idx_buf[i] != 0; i++) | |
{ | |
int idx; | |
if (idx_buf[i] == 1) | |
{ | |
idx = i; | |
printf ("argument %d has hyphen : %s\n", i, str[idx]); | |
} | |
else if (idx_buf[i] == 2) | |
{ | |
idx = i; | |
printf ("argument %d has no hyphen : %s\n", i, str[idx]); | |
} | |
} | |
return 0; | |
} |
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
/* Take arguments and output if it's after hyphen one. */ | |
#include <stdio.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; | |
} | |
i = 0; | |
while (num) | |
{ | |
int j; | |
for (j = 0; str[i] != '\0'; j++) | |
{ | |
if (str[i][j] == '-') | |
{ | |
idx_buf[i] = 1; | |
i++; | |
break; | |
} | |
else | |
{ | |
idx_buf[i] = 2; | |
i++; | |
break; | |
} | |
} | |
num--; | |
} | |
i = 1; | |
while (idx_buf[i] != 0) | |
{ | |
int idx; | |
if (idx_buf[i] == 1) | |
{ | |
i++; | |
if (idx_buf[i] == 2) | |
{ | |
idx = i; | |
printf ("argument %d after hyphen: %s\n", i, str[idx]); | |
i++; | |
continue; | |
} | |
} | |
else | |
i++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment