For my final project I am supposed to design a game of War. My main question is, after reading a file (Deck of 52) and initializing an array to have all the number cards. My question is, how do you split that array into two random hands?
Here's a sample of my code in case it is needed, but I just need to know how the random function works. And if there's any suggestions.
/*
This program will make a game of war between two players
*/
#include<stdio.h>
#include<math.h>
int main(void)
{
int i,j; //iterators
int Deck[13][4];//array for the Deck of 52
int P1[13][2];//Player 1 array
int P2[13][2];//Player 2 array
FILE* inCards;//file to read
inCards=fopen("cards.txt", "r");
if(inCards==NULL)
{
printf("Could not open file.");//either we typed it wrong or the file is fucked
}
else
{
for(i=0;i<13;i++)//Intialize the array
{
for(j=0;j<4;j++)
{//Initialize the array and make sure it stops at the end of the file
if (fscanf(inCards,"%d",&Deck[i][j])==EOF)//If the file reaches the end, it'll mark an error.
{
printf("error");
}
}
}
}
//FIND WAY TO RANDOMIZE THE DECK INTO TWO PLAYER HANDS
fclose(inCards);
printf("******\n* *\n* %d *\n* *\n******");//Wartime Display
return(0);
}