-
Notifications
You must be signed in to change notification settings - Fork 0
/
readWord_with _inderline_after_commf.c
52 lines (43 loc) · 1.48 KB
/
readWord_with _inderline_after_commf.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
//пробелы добавляются после каждой запятой
Word readWord() {
int size = MEMORY_STEP;
int len = 0;
wchar_t *chars = malloc(size * sizeof(wchar_t));
wchar_t sep, symbol = L' ';
while (symbol == L' ')
symbol = getwchar();
while ((!wcschr(WORD_SEP, symbol)) && (!wcschr(SENTENCE_SEP, symbol))) {
if (symbol == L'\n') newlineCounter++;
else newlineCounter = 0;
if (newlineCounter == 2) break;
if (symbol != L'\n') {
if (len > 0 && chars[len - 1] == L'.') {
} else {
chars[len++] = symbol;
}
} else if (len > 0 && chars[len - 1] != L'.') {
chars[len++] = symbol;
}
if (len == size) {
size += MEMORY_STEP;
chars = (wchar_t *)realloc(chars, size * sizeof(wchar_t));
}
symbol = getwchar();
if (symbol == L',') {
if (len == size) {
size += MEMORY_STEP;
chars = (wchar_t *)realloc(chars, size * sizeof(wchar_t));
}
chars[len++] = symbol;
if (len == size) {
size += MEMORY_STEP;
chars = (wchar_t *)realloc(chars, size * sizeof(wchar_t));
}
chars[len++] = L' ';
symbol = getwchar();
}
}
chars[len] = L'\0';
sep = symbol;
return (Word) {chars, sep, len};
}