Как удалить слово с строки( char[] )

Задача по символьных массивах C ++. Нужно в написанном в консоль строке:

  1. Удалить все слова с двумя буквами подряд.
  2. Посчитать количество слов в предложении и количество использованных символов.

Со вторым вроде как все понятно. А в первом никак не получается.

#include <iostream>

using namespace std;

void getStr(char*);
void removeWord(char*);
void countWordSymbol(char*);

int main()
{
    char str[255];

    getStr(str);
    removeWord(str);
    countWordSymbol(str);
    
}

void getStr(char* str)
{
    cin.get(str, 255);
}

void removeWord(char* str)
{
    char strCopy[255];
    strcpy(strCopy, str);

    char* ptr;
    int length;
    
    ptr = strtok(strCopy, " ");
    
    while (ptr != NULL)
    { 
        length = strlen(ptr);
        cout << ptr << " " << length << endl;

        for(int i = 0; i < length; i++)
            if(ptr[i] == ptr[i+1])
                strcpy(strCopy, ptr);

        ptr = strtok(NULL, " ");
    }

    cout << "Changed String: " << strCopy << endl;

}

void countWordSymbol(char *str)
{
    char* strPtr;
    int count = 0;
    size_t length = strlen(str);

    strPtr = strtok(str, " ");

    while (strPtr != NULL)
    {
        count++;
        strPtr = strtok(NULL, " ");
    }

    cout << "Number of word: " << count << endl << "Number of used symbol: " << length << endl;
}

Ответы (1 шт):

Автор решения: megorit

Как-то так:

char ch;
std::vector<char> word;

while (std::cin >> ch)
    if (std::isalpha(ch))
        word.push_back(ch);
    else {
        if (!word.empty()) {
            if (!hasDoubleAlpha(word))
                std::cout << word;
            word.clear();
        }
        std::cout << ch;
    }

if (!word.empty() && !hasDoubleAlpha(word))
    std::cout << word;

Без std::vector:

char ch;
char word[50+1];
int index = 0;

while (std::cin >> ch)
    if (std::isalpha(ch)) {
        word[index] = ch, word[++index] = '\0';
    } else {
        if (std::strlen(word) > 0) {
            if (!hasDoubleAlpha(word))
                std::cout << word;
            index = 0;
        }
        std::cout << ch;
    }

if (std::strlen(word) > 0 && !hasDoubleAlpha(word))
    std::cout << word;
→ Ссылка