codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Arrays - Big Problem  midnightlycoder at 17:44 on Friday, March 23, 2007
 

Hello all. Long time reader, first time poster.

My problem is pretty huge, and I don't even really know where to start explaining lol.

Basically what is happening is I'm expecting the arrays, cardvalue[] in particular, to only fill with 52 numbers. I'm initializing them to 52, but when I pass to the "FillShuffle" function, the outcome is extremely unexpected.

After being passed and "filled", the arrays somehow are combining into each other. For example, doing a display of the elements in "cardvalue[]", comes up with the first 0-51 elements containing the correct numbers, but element 53 (52 in actuality) and up contain, for some strange reasons, the other array elements?

For instance, cardvalue[53] will contain straightflushnumber[0], cardvalue[54] will contain straightflushnumber[1], etc.

Very strange, and it is creating a problem with the shuffle function. Even weirder, which arrays are affected change when i change the order of initialization.

For instance, if i "int cardvalue[52], cardsuit[52], straightflushnumber[52]", than cardvalue[53] will be equal to cardsuit[53] instead of straightflushnumber[53].

Eghads, lots of problems, but hopefully i will find a way to fix it with you guys' help.

And now, my code. I'm not the greatest programmer right now, and I know there's better ways of doing things, but for now I'd just like to understand why the array combining thing is happening.

Without further ado:

[code]


int cardcounter;
// Card Class
struct Card {
int number;
char *cardname;
int value;
int cardsui;
int villain2;
int straightflu;
int straightac;
char *cardname2;
};

// Function declerations for filling, and shuffling the deck
void fillDeck(Card * const, char *[], int [], int[], int[], char *[], int[], int[]);
void shuffle(Card * const);

// Arrays to keep track of values
char * cardfilename[52];
char * cardfilename2[52];
int cardvalue[52];
int straightflushnumber[52]
int cardvillain2[52];
int straightacenumber[52];
int cardsuit[52];

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void __fastcall TForm1::ShuffleFill(TObject *Sender)
{

handdeterminecounter == 1;
// Card Dealing Variables
Card deck[52];
int number[] = {1};
int value[52] = {1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13};
int villain2[52] = {14,2,3,4,5,6,7,8,9,10,11,12,13,14,2,3,4,5,6,7,8,9,10,11,12,13,14,2,3,4,5,6,7,8,9,10,11,12,13,14,2,3,4,5,6,7,8,9,10,11,12,13};
char *cardname[52] = { "cards/diamondsace.bmp", "cards/diamondstwo.bmp", "cards/diamondsthree.bmp", "cards/diamondsfour.bmp", "cards/diamondsfive.bmp", "cards/diamondssix.bmp", "cards/diamondsseven.bmp", "cards/diamondseight.bmp", "cards/diamondsnine.bmp", "cards/diamondsten.bmp", "cards/diamondsjack.bmp", "cards/diamondsqueen.bmp", "cards/diamondsking.bmp", "cards/heartsace.bmp", "cards/heartstwo.bmp", "cards/heartsthree.bmp", "cards/heartsfour.bmp", "cards/heartsfive.bmp", "cards/heartssix.bmp", "cards/heartsseven.bmp", "cards/heartseight.bmp", "cards/heartsnine.bmp", "cards/heartsten.bmp", "cards/heartsjack.bmp", "cards/heartsqueen.bmp", "cards/heartsking.bmp", "cards/spadesace.bmp", "cards/spadestwo.bmp", "cards/spadesthree.bmp",
"cards/spadesfour.bmp", "cards/spadesfive.bmp", "cards/spadessix.bmp", "cards/spadesseven.bmp", "cards/spadeseight.bmp", "cards/spadesnine.bmp", "cards/spadesten.bmp", "cards/spadesjack.bmp", "cards/spadesqueen.bmp", "cards/spadesking.bmp", "cards/clubsace.bmp", "cards/clubstwo.bmp", "cards/clubsthree.bmp", "cards/clubsfour.bmp", "cards/clubsfive.bmp", "cards/clubssix.bmp",
"cards/clubsseven.bmp", "cards/clubseight.bmp", "cards/clubsnine.bmp", "cards/clubsten.bmp", "cards/clubsjack.bmp", "cards/clubsqueen.bmp", "cards/clubsking.bmp"};
int cardsuit[52] = {1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4};
char *cardname2[52] = { "cards/diamondsace.bmp", "cards/diamondstwo.bmp", "cards/diamondsthree.bmp", "cards/diamondsfour.bmp", "cards/diamondsfive.bmp", "cards/diamondssix.bmp", "cards/diamondsseven.bmp", "cards/diamondseight.bmp", "cards/diamondsnine.bmp", "cards/diamondsten.bmp", "cards/diamondsjack.bmp", "cards/diamondsqueen.bmp", "cards/diamondsking.bmp", "cards/heartsace.bmp", "cards/heartstwo.bmp", "cards/heartsthree.bmp", "cards/heartsfour.bmp", "cards/heartsfive.bmp", "cards/heartssix.bmp", "cards/heartsseven.bmp", "cards/heartseight.bmp", "cards/heartsnine.bmp", "cards/heartsten.bmp", "cards/heartsjack.bmp", "cards/heartsqueen.bmp", "cards/heartsking.bmp", "cards/spadesace.bmp", "cards/spadestwo.bmp", "cards/spadesthree.bmp",
"cards/spadesfour.bmp", "cards/spadesfive.bmp", "cards/spadessix.bmp", "cards/spadesseven.bmp", "cards/spadeseight.bmp", "cards/spadesnine.bmp", "cards/spadesten.bmp", "cards/spadesjack.bmp", "cards/spadesqueen.bmp", "cards/spadesking.bmp", "cards/clubsace.bmp", "cards/clubstwo.bmp", "cards/clubsthree.bmp", "cards/clubsfour.bmp", "cards/clubsfive.bmp", "cards/clubssix.bmp",
"cards/clubsseven.bmp", "cards/clubseight.bmp", "cards/clubsnine.bmp", "cards/clubsten.bmp", "cards/clubsjack.bmp", "cards/clubsqueen.bmp", "cards/clubsking.bmp"};
int straightflushnumber[52] = {1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,55};
int straightacenumber[52] = {14,2,3,4,5,6,7,8,9,10,11,12,13,29,17,18,19,20,21,22,23,24,25,26,27,28,44,32,33,34,35,36,37,38,39,40,41,42,43,58,46,47,48,49,50,51,52,53,54,55,56,57};

// Randomize
srand(time(0));
fillDeck(deck, cardname, value, villain2, cardsuit, cardname2, straightflushnumber, straightacenumber);
//shuffle(deck);

// Start Seat counter
seatcounter = 1;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void fillDeck(Card * const wDeck, char *wCardname[], int wValue[], int wVillain2[], int wCardsui[], char *wCardname2[], int wStraightflu[], int wStraightac[])
{
int k;
k = 1;

for(int i = 0; i < 52; i++)
{
//int placeholder = (i % 52);
wDeck.number = k;
k++;
// Temporary Setup
wDeck.cardname = wCardname;
wDeck.value = wValue;
wDeck.villain2 = wVillain2;
wDeck.cardsui = wCardsui;
wDeck.cardname2 = wCardname2;
wDeck.straightflu = wStraightflu;
wDeck.straightac = wStraightac;
// Temporary Setup 2
cardfilename = wDeck.cardname;
cardfilename2 = wDeck.cardname2;
cardvalue = wDeck.value;
cardvillain2 = wDeck.villain2;
cardsuit = wDeck.cardsui;
straightflushnumber = wDeck.straightflu;
straightacenumber = wDeck.straightac;
}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void shuffle(Card * const wDeck)
{
for ( int i = 0; i < 52; i++ )
{
int j = rand() % 52;
Card temp = wDeck;
wDeck = wDeck[j];
wDeck[j] = temp;
cardfilename = wDeck.cardname;
cardfilename2 = wDeck.cardname2;
cardvalue = wDeck.value;
cardvillain2 = wDeck.villain2;
cardsuit = wDeck.cardsui;
straightflushnumber = wDeck.straightflu;
straightacenumber = wDeck.straightac;
Form1->Button5->Click();
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

[/code]

I know this is probably a very confusing problem, but hopefully someone will be able to offer a bit of advice, that will lead to more thinking on my part, and eventually, a solution :)









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Perl - Read and Write output file
•  Re: Print and print preview file on the website without using the File - Print on the IE
•  Re: While Loops - Help please!
•  trying to write dates from perl to Excel
•  5x5 Tic Tac Toe
•  NEED HELP!!!! Password encryption
•  positioning ContentPlaceHolder
•  Arrays - Big Problem
•  problem in grid view


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007