-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDiv.cpp
44 lines (42 loc) · 949 Bytes
/
Div.cpp
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
#include "Div.h"
char** divideText(char source[], int size) // ôîðìèðîâàíèå ìàññèâà ñòðîê, ñîñòîÿùåãî èç ëåêñåì
{
char** word = new char* [max_world];
for (int i = 0; i < max_world; i++)
word[i] = new char[size_world] {NULL};
bool findSP, findLit = false;
int j = 0;
char SP[] = { " ,;(){}=+-*/|" };
for (int i = 0, k = 0; i < size - 1; i++, k++)
{
findSP = false;
if (source[i] == '\'')
findLit = !findLit;
for (int t = 0; t < sizeof(SP) - 1; t++)
{
if (source[i] == SP[t] && !findLit)
{
findSP = true;
if (word[j][0] != NULL) {
word[j++][k] = '\0';
k = 0;
}
if (SP[t] == ' ') {
k = -1;
break;
}
word[j][k++] = SP[t];
word[j++][k] = '\0';
k = -1;
break;
}
}
if (!findSP)
word[j][k] = source[i];
}
word[j] = NULL;
for (int i = 0; i < j; i++)
if (!strcmp((char*)word[i], ""))
return NULL;
return word;
}