-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c.bak
More file actions
109 lines (95 loc) · 1.82 KB
/
test.c.bak
File metadata and controls
109 lines (95 loc) · 1.82 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define LENGTH 40
#define DATASIZE 128
#define BYTE 8
#define ARRAY ((DATASIZE) / (BYTE))
char delimiters[LENGTH] = " ,'\n'";
typedef struct
{
char set;
char data[ARRAY];
}Set;
void read_prepare(char *pstr)
{
Set *group;
printf("pstr<%s>\n", pstr);
pstr = strtok((char *)NULL, delimiters);
if (!check_group_name(pstr))
{
printf("No such set: %s\n", pstr);
return;
}
group->set = pstr;
printf("group<%s>\n",group->set);
}
void print_prepare(char *pstr)
{
printf("pstr<%s>\n", pstr);
return;
}
void union_prepare(char *pstr)
{
printf("pstr<%s>\n", pstr);
return;
}
void intersect_prepare(char *pstr)
{
printf("pstr<%s>\n", pstr);
return;
}
void sub_prepare(char *pstr)
{
printf("pstr<%s>\n", pstr);
return;
}
void halt(char *pstr)
{
printf("pstr<%s>\n", pstr);
exit(0);
}
typedef struct
{
char *function_name;
void (*pt2Func) (char *);
} prepare_t;
prepare_t function_array[] = {
"read_set", read_prepare,
"print_set", print_prepare,
"union_set", union_prepare,
"intersect_set", intersect_prepare,
"sub_set", sub_prepare,
"halt", halt,
0, 0
};
main()
{
char string1[LENGTH];
char *pstr, *function;
prepare_t *tmp;
while (1)
{
printf("Enter the string to be searched: ");
fgets(string1, LENGTH, stdin);
pstr = strtok(string1, delimiters);
for (tmp = function_array; tmp->function_name; tmp++)
if (strcmp(pstr, tmp->function_name) == 0)
tmp->pt2Func(tmp->function_name);
}
}
char * check_group_name(char *group)
{
if (*group >= 'A' && *group <= 'F')
return group;
return '\0';
}
void bitprint(unsigned x)
{
int b;
for (b = 0; x != 0;b++, x >>= 1)
if (x & 01)
printf("%d ", b);
printf("\n");
}