/
remchr.c
49 lines (45 loc) · 892 Bytes
/
remchr.c
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
/* ex: set ts=8 noet: */
#include <stdio.h>
#include <string.h>
static void remchr(const char *in, char *out, const int c)
{
while ((*out = *in))
out += (*in++ != c);
}
main()
{
static const struct {
int c;
char *in,
*out;
} Test[] = {
{ 'A', "ABC", "BC" },
{ 'A', "AAC", "C" },
{ 'A', "AAA", "" },
{ 'A', "ABA", "B" },
{ 'A', "BAC", "BC" },
{ 'A', "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "" },
{ 'D', "ABC", "ABC" }
}, *T;
char buf[64];
size_t i;
unsigned N = 10000000;
while (N--) {
T = Test;
i = sizeof Test / sizeof Test[0];
while (i--) {
#if 0
printf("#%u \"%s\" - '%c' -> \"%s\" (",
(unsigned)(T - Test), T->in, T->c, T->out);
fflush(stdout);
#endif
strcpy(buf, T->in);
remchr2(buf, buf, T->c);
#if 0
printf("\"%s\") [%s]\n", buf, 0 == strcmp(buf, T->out) ? "OK" : "!!");
#endif
T++;
}
}
return 0;
}