1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#define MAX 5
int get_members(char *s, char *members[]) {
int count = 0;
int b_space = 1;
while (*s) {
if (isspace(*s)) {
*s = '\0';
b_space = 1;
if (count == MAX)
break;
} else if (b_space) {
members[count++] = s;
b_space = 0;
}
s++;
}
return count;
}
void main() {
printf("input some menbers(max: 5) ? ");
char buf[100];
fgets(buf, 100, stdin);
char *members[5];
int n = get_members(buf, members);
if (n == 0) {
printf("members is empty.\n");
} else {
srand((unsigned)time(NULL));
printf("lucky guy is %s!\n", members[rand() % n]);
}
}