-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathwc2o.c
More file actions
26 lines (24 loc) · 682 Bytes
/
wc2o.c
File metadata and controls
26 lines (24 loc) · 682 Bytes
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
/*
An Obfuscated-C version of 'wc' using state-machines
*/
#include <stdio.h>
int main(void)
{
static const unsigned char table[4][3] = {
{2,0,1}, {2,0,1}, {3,0,1}, {3,0,1}
};
static const unsigned char column[256] = {
0,0,0,0,0,0,0,0,0,1,2,1,1,1,0,0,0, /* \t\n\v\f\r */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* SPACE ' ' */
};
unsigned long counts[4] = {0,0,0,0};
int state = 0;
int c;
while ((c = getchar()) != EOF) {
state = table[state][column[c]];
counts[state]++;
}
printf("%lu %lu %lu\n", counts[1], counts[2],
counts[0] + counts[1] + counts[2] + counts[3]);
return 0;
}