C/C++

Помогите написать код c++ со строками

Ввести с клавиатуры строку и удалить из строки слова содержащие четное количество символов. Слова разделены одними или несколькими пробелами. (БЕЗ ИСПОЛЬЗОВАНИЯ БИБЛИОТЕКИ STRING)
Сергей М
Сергей М
27
#include <iostream>
using namespace std;
size_t count_words(char* line) {
size_t i = 0;
while (line[i] && line[i] == ' ') ++i;
if (!line[i] || line[i] == '\n') return 0;
size_t count = 0;
do {
while (line[i] && line[i] != ' ') ++i;
++count;
while (line[i] == ' ' || line[i] == '\n') ++i;
} while (line[i]);
return count;
}
size_t string_length(char* line) {
size_t len = 0;
while (line[len]) ++len;
return len;
}
void string_copy(char* dest, const char* src) {
int i = 0;
do dest[i] = src[i]; while (src[++i]);
dest[i] = 0;
}
void string_copy(char* dest, const char* src, const size_t n) {
size_t i = 0;
do dest[i] = src[i]; while (++i < n);
dest[i] = 0;
}
char* string_token(char* line, const char delim = ' ') {
static char* tmp = nullptr;
static size_t i = 0;
static size_t length = 0;
static char* token = nullptr;
if (line != nullptr) {
length = string_length(line) + 1;
tmp = new char[length];
token = new char[length];
string_copy(tmp, line);
}
while (tmp[i] && tmp[i] == delim) ++i;
size_t n = 0;
size_t j = i;
while (tmp[j] && tmp[j] != delim) {
++n;
++j;
}
if (n) {
string_copy(token, tmp + i, n);
i = j;
} else {
delete[] tmp;
delete[] token;
tmp = token = nullptr;
length = i = 0;
}
return token;
}
void string_concat(char* dest, const char* src) {
size_t i = string_length(dest);
size_t j = 0;
while (src[j]) {
dest[i] = src[j];
++i;
++j;
}
dest[i] = 0;
}
bool is_odd(char* word) {
return string_length(word) & 1;
}
void erase_even_length(char* line) {
size_t n = count_words(line);
char** words = new char* [n];
size_t m = string_length(line) + 1;
for (size_t i = 0; i < n; ++i) words[i] = new char[m];
char* token = string_token(line);
if (token) {
size_t i = 0;
string_copy(words[i], token);
while (token != nullptr) {
token = string_token(nullptr);
if (token) string_copy(words[++i], token);
}
char* tmp = new char[m];
tmp[0] = 0;
for (size_t i = 0; i < n; ++i) {
if (is_odd(words[i])) {
if (tmp[0]) string_concat(tmp, " ");
string_concat(tmp, words[i]);
}
}
string_copy(line, tmp);
}
}
int main() {
char line[] = "defghi abc defg abcde hijklm xyz hi";
puts(line);
erase_even_length(line);
puts(line);
system("pause > nul");
}

P.S. Очень надеюсь, что после этого вы полюбите STL.
Никитин Никита
Никитин Никита
68 630
Лучший ответ
Сергей М огромное спасибо
Сергей М только вот я же указал, что строку надо ввести с клавиатуры
Сергей М Всё, я разобрался
Сергей М хочу еще задать вопрос касаемо size_t. В чем его преимущества и когда его лучше использовать
Сергей М Понял, спасибо