-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.cpp
More file actions
33 lines (30 loc) · 772 Bytes
/
helpers.cpp
File metadata and controls
33 lines (30 loc) · 772 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
27
28
29
30
31
32
33
#include <bits/stdc++.h>
#include <arpa/inet.h>
/* Functia converteste un string de tip char* intr-un string */
std::string convertToString(char* a, int size)
{
int i;
std::string s = "";
for (i = 0; i < size; i++) {
if (a[i] == '\n')
return s;
s = s + a[i];
}
return s;
}
/* Functia returneaza size-ul unui string de tip char* */
int char_size(char *str) {
int i = 0;
while (ntohs(str[i]) != '\0')
i++;
return i;
}
/* Functia imparte un string dupa delimitatori */
void split (char *str, char *delim, std::vector<std::string> &strings)
{
char* token = strtok(str, delim);
while (token != NULL) {
strings.push_back(convertToString(token, char_size(token)));
token = strtok(NULL, delim);
}
}