String Shuffling

string tempwordhold[2][9] = {"ALL IS WELL"};

void shuffle()
{
int x, y;
string word,temp;

word = tempwordhold[currentCat][currentQuestion];
x=word.length();

srand(time(0));
while(x!=0){
int y=rand()%x;
temp+=word[y];
word[y]=word[x-1];
word=word.substr(0,(x-1));
x--;
}
cout<<temp;
}

i want to shuffle a string and it did run quite nicely if it is only one word but i need help in shuffling a sentence because shuffling the string "ALL IS WELL" turns out to be "WL ASIL ELL", and i hoped i could just make it word-per-word shuffling like "LAL SI LEWL". Please help
Just get each word out of the string individually (probably using substr), then you can just shuffle that. Then just print them back out or concatenate them as needed.
but i don't know how to loop my existing shuffle() routine to process long strings, and i need to store them back to the same variable so i might go crazy with concat. :/
Topic archived. No new replies allowed.