A sentence is given in which words are separated by spaces (one or more). Change each word in the line, removing from it all subsequent occurrences of the first letter of this word (do not change the number of spaces between words).
#include <iostream>
#include <cstring>
using namespace std;
void check(char *input){
char* Letter = strtok(input, " ");
while (Letter){
char _Letter = Letter[0];
for (int i = 1; i < strlen(Letter); i++)
if (Letter[ i ] == _Letter)
Letter[ i ] = ' ';
cout << Letter << " ";
Letter = strtok(NULL, " ");
}
cout << endl;
}
int main(){
setlocale(LC_ALL , "Ukrainian");
char *input = new char[100];
gets(input);
check(input);
delete[] input;
return 0;
}
My code removes the occurrence of the first letter from the word, but does not take into account the spaces between words and leaves one space.Using std :: string is not allowed, you must use a character array with functions from the library <string.h> Help fix the code, please