|
|
1.1 root 1: /*
2: * One or more characters matching some criterion.
3: * span(s1, matcher, fin)
4: */
5: #include <stdio.h>
6: char *
7: span(s1, matcher, fin)
8: register char *s1;
9: int (*matcher)();
10: register char **fin;
11: {
12: char c;
13: char *start = s1;
14:
15: for (*fin = NULL; (c = *s1++) && (*matcher)(c); *fin = s1)
16: ;
17: if (NULL == *fin)
18: return (NULL);
19: return (start);
20: }
21: #ifdef TEST
22: #include <ctype.h>
23: #include "local_misc.h"
24:
25: /* eliminate under ansi */
26: digit(s)
27: char s;
28: {
29: return (isdigit(s));
30: }
31:
32: main()
33: {
34: char s1[80], *fin;
35:
36: for (;;) {
37: ask(s1, "s1");
38: if (!strcmp(s1, "quit"))
39: exit(0);
40: if (NULL == span(s1, digit, &fin))
41: printf("No digits\n");
42: else {
43: *fin = '\0';
44: printf("%s\n", s1);
45: }
46: }
47: }
48: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.