I want to cut a tring in half then take each number from eack half and put them on top like this:
1 2 3 4 5 6 7
cut the string in half
1 2 3 4 5 6 7
shuffle
3 7 2 6 1 5 4
any idea on how to do that....thanks
I want to cut a tring in half then take each number from eack half and put them on top like this:
1 2 3 4 5 6 7
cut the string in half
1 2 3 4 5 6 7
shuffle
3 7 2 6 1 5 4
any idea on how to do that....thanks
There are many ways to do this.
For a quick hack, something like that should work.Code:for( w = x = 0, y = z = strlen(a)/2; x < z && y < strlen(a); x++,y++) { array[w++]=a[x]; array[w++]=a[y]; }
Quzah.
Hope is the first step on the road to disappointment.
Thanks for the help...
Now if I want to keep on cutting the deck and shuffling till I get to the original .....how do I do it?
Here is my code, but for some reason it is not working?
Code:int w,x,y,z,k; int count=0; char values[]={'1','2','3','4','5','6','7','8'}; for( w = x = 0, y = z = strlen(values)/2; x < z && y < strlen(values); x++,y++ ) { theDeck[w++]=values[x]; theDeck[w++]=values[y]; count++; } int count2=0; for(;;) { for( w = x = 0, y = z = strlen(values)/2; x < z && y < strlen(values); x++,y++ ) { theDeck2[w++]=theDeck[x]; theDeck2[w++]=theDeck[y]; count2++; } if (values==theDeck2) break; else for( w = x = 0, y = z = strlen(values)/2; x < z && y < strlen(values); x++,y++ ) { theDeck[w++]=theDeck2[x]; theDeck[w++]=theDeck2[y]; count2++; } if (values==theDeck2) break; else continue; } puts(count2);
It seems that my program goes into an endless loop!!!!
I'm not too sure what you're up to, but this is definately wrong:
>if (values==theDeck2) break
You cannot compare arrays like this.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
One wonders why...Originally posted by *Tim*
It seems that my program goes into an endless loop!!!!
for(;;)
Quzah.
Hope is the first step on the road to disappointment.
This is what I am trying to do.....
I want to cut a deck of 52 cards in half then take each number from from the bottom of the half pile and put them on top like this:
I then want to keep on shuffling in the same manner till I get to the original full deck
example:
1 2 3 4 5 6 7 8
cut the string in half
1 2 3 4..... 5 6 7 8
shuffle
1 5 2 6 3 7 4 8
any idea on how to do that....thanks
You want to keep shuffling until it is back to the original array? What for? Anyway, just duplicate the original string, and use strcmp to make sure they end up the same.I then want to keep on shuffling in the same manner till I get to the original full deck
Quzah.
Hope is the first step on the road to disappointment.