I am currently working on my school project (Piglatin) and we are required to remove all the special characters that the user enters except for the last one. My code right now deletes all the special characters including the last punctuation. My idea is to save the last character, if it's a punctuation, and add it later after I cleaned up the user input. But I'm having a hard time reflecting my idea into my code. Please help. I'm really trying. I'm open to any suggestions.
Word *getInput (string userInput, int &size)
{
int i = 0;
size = wordCounter(userInput); // Get the number of words
Word *field = new Word[size]; //allocate struct Word
//removes special characters
char chars[] = "!@~`#$%^&*()_-+={}[]|\'<,>.?/";
for(unsigned int i = 0; i< strlen(chars); ++i )
{
userInput.erase(remove(userInput.begin(), userInput.end(), chars[i]) ,userInput.end());
}
for (int i = 0; userInput[i] != '\0'; i++)
{
userInput[i] = tolower(userInput[i]);
}
for (int i = 0; i < size; i++)
{
field[i].english = userInput;
}
cout << field[i].english<< endl;
return field;
}
Aucun commentaire:
Enregistrer un commentaire