-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_tokenizer.cpp
More file actions
50 lines (35 loc) · 1.09 KB
/
string_tokenizer.cpp
File metadata and controls
50 lines (35 loc) · 1.09 KB
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
#include <cstring>
#include <iostream>
#include <string>
char *string_tokenizer(const char *input_str, const char *tokens);
int main() {
std::string msg{"I am a C/C++ Developer ..."};
char *buff = string_tokenizer(msg.c_str(), "");
std::cout << "--------------------------" << '\n';
std::cout << buff << '\n';
for (char *c = buff; *c; c++) {
std::cout << *c << '\n';
}
std::cout << "--------------------------" << '\n';
std::cout << "\nThe End ..." << std::endl;
return EXIT_SUCCESS;
}
char *string_tokenizer(const char *input_str = "", const char *tokens = "") {
size_t counter{};
bool accept{};
char *buff = static_cast<char *>(calloc(strlen(input_str), sizeof(char)));
memset(buff, '\0', strlen(buff));
for (const char *in_str = input_str; *in_str; in_str++) {
accept = true;
for (const char *c = tokens; *c; c++) {
if (*in_str == *c) {
accept = false;
break;
}
}
if (accept) {
buff[counter++] = *in_str;
}
}
return buff;
}