edit: I guess long story short is how do you save and detect spaces in a string vector? Because the way I've been trying isn't working.
When I test output it looks empty with the vector item which would work except how do I detect an empty string vector element because in the case of double spaces I need my output string to have double spaces (no "ay" and right now that's what it gives)
Not homework, just practice I'm doing on another website but I'm very stuck on this. I'm soo close but it fails the random tests involving input with multiple space inputs.
Goal: Pig latin any input sentence (can be a word or sentence and can include non characters like ! ) So take the first letter and put it at the end with "ay" attached to it.
Like I said, it works on everything except the random tests involving double spaces. From what I can tell when I fill my vector it sometimes saves and sometimes doesn't save the space I'm trying to detect in:
1 2 3 4 5 6 7
for (int i = 0; i < str.length(); i++ ) {
if (str[i] == ' ') {
if (str[i+1] == ' ') {
words.push_back(" ");
i++;
word = "";
}
Then when I try and detect it, it doesn't detect. I've tried lots of ways of detecting spaces including isspace
1 2 3 4 5 6 7 8 9 10 11
// last word == 1
} elseif ( count == words.size()-1 && w.length() == 1 ) {
if ( w == "" || w == " ") {
pigged += " ";
cout << "appended spaces#2" << endl;
break;
} elseif ( !(isalpha(w[0])) ) {
pigged += w;
break;
}