forked from aabyaneh/benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
word_count.c
75 lines (61 loc) · 1.3 KB
/
word_count.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
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
uint64_t CHAR_EOF = -1;
uint64_t CHAR_TAB = 9;
uint64_t CHAR_LF = 10;
uint64_t CHAR_CR = 13;
uint64_t CHAR_SPACE = ' ';
uint64_t line_number = 0;
uint64_t word_number = 0;
uint64_t byte_number = 0;
uint64_t is_character_new_line(uint64_t c) {
if (c == CHAR_LF)
return 1;
else if (c == CHAR_CR)
return 1;
else
return 0;
}
uint64_t is_character_whitespace(uint64_t c) {
if (c == CHAR_SPACE)
return 1;
else if (c == CHAR_TAB)
return 1;
else
return is_character_new_line(c);
}
void wc(uint64_t* s) {
while (*s != CHAR_EOF) {
while (is_character_whitespace(*s) == 1) {
if (*s == CHAR_LF) {
line_number = line_number + 1;
}
byte_number = byte_number + 1;
s = s + 1;
}
if (*s != CHAR_EOF) {
word_number = word_number + 1;
byte_number = byte_number + 1;
s = s + 1;
while (is_character_whitespace(*s) == 0) {
if (*s == CHAR_EOF)
return;
byte_number = byte_number + 1;
s = s + 1;
}
}
}
}
uint64_t main() {
uint64_t* str;
uint64_t cnt;
uint64_t i;
cnt = 8;
str = malloc(cnt * 8);
i = 0;
while (i < cnt-1) {
interval((str + i), 5, 125, 1);
i = i + 1;
}
*(str + cnt-1) = -1;
wc(str);
return 0;
}