what am i doing wrong

void jumbleString (string str)
{
int length = str.length();
int j, k;


for(int i = 0; i < length; i++)
{
i = rand() % length;
j = rand()%length;
char c = str[j];
str[j] = str[k];
str[k] = c;
}

cout << str<<endl;
}
You aren't actually modifying str, you are modifying a copy of str. Pass it by reference (or pointer) if you want to modify it.
i wanted to create a function where i would enter a string and it would output a jumbled string
Topic archived. No new replies allowed.