### Shuffling an array not executing properly?

closed account (4iwkoG1T)
Hi, there. I have a 2D array with 208. I must concatenate the strings by twos up to index 199.
So that I have 108 strings. Then I must shuffling these 108 strings.
The problem is that it isn't working right. After I concatenate the strings, then shuffle, several strings un concatenate again.
Ex:
born dramatic insurance gravy release frying
costume despair mission gibberish backyard abusive

I want to only concatenate the first 10 strings.
Result:
borndramatic insurancegravy releasefrying
costumedespair missiongibberish backyard abusive

Then shuffle:
abusive releasefrying backyard costumedespair
borndramatic missiongibberish insurancegravy

This is what my functions do:
abusive dramatic releasefrying gravy backyard costumedespair
borndramatic missiongibberish despair insurancegravy

It copies the second string again.
Last edited on
closed account (4iwkoG1T)
I think the problem is in the concatenation function.
 ``123456789101112131415`` ``````void Concatenation( char dest[208][13] ) { for(int i=0; i<208 && i<200; i+=2) // i < 208 concatenates all 208. // if I change to i < 200. { myStrCat(dest[i],dest[i+1]); // myStrCat is equal to strcat(). // cout << dest[i] << " "; // outputs the first 100. } for(int i=200; i<208; i++) { // cout << dest[i] << " "; // outputs the last 8. } ``````

 ``1234567891011121314`` ``````void ShuffleArray( char destination[208][13] ) { char temp[13]; for (int i = 0 ; i < 208 ; i++) { int m = rand() % 108; myStrCpy(temp,destination[m]); // myStrCpy is strcpy() myStrCpy(destination[m],destination[i]); myStrCpy(destination[i],temp); } }``````
Last edited on
Topic archived. No new replies allowed.