New Smaller and Smaller Arrays.
I want to make a card game, where you pick a card, and then, you pick another card from the cards that are left. I started by making an array with another smaller array where the numbers(later cards) are assigned to it using the numbers(later cards) that are left.
My questions are this?
1.) does this program compile and run on other people's systems, it seems to work okay on mine?
2) How come it seems like C just makes the second array longer? Is that going to cause me problems down the road when I put the cards and more stuff in the program?
3) I've read things about some card shuffling algorithms. I've read some of the more popular ones are really bad and not random enough cause some cards end up being picked more than others. One I found, I tried using 5 cards and a sheet of paper, and found it was just as bad as it said. I figure with my algorithm of just picking a card, then another card, then another card randomly, it should always be random.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main (){
int tablestu [] = { 10, 20, 30, 40, 50};
int table2 [4];
/*for (int i= 0; i< 5; i++) */
int i = 0;
while (i < 5 ){
printf("Hi, %d hello %d \n", i, tablestu[i]);
i++;
}
unsigned int iseed = (unsigned int)time(NULL);
srand(iseed);
int genme = (rand() % 5 );
printf("Int genme %d \n",genme);
int h = 0;
while( h < 5){
if (h = tablestu[genme])
printf("this is the card %d \n",tablestu[genme]);
h++;
}
int k = 0;
while (k < 5) {
if (k == genme)
{
table2[k] = tablestu[k+1];
}
else if ( k < genme)
{
table2[k] = tablestu[k];
}
else {
table2[k] = tablestu[k+1];
}
k++;
}
int j = 0;
while (j < 5 ){
printf("Hi, %d hello2 %d \n", j, table2[j]);
j++;
}
int m = 0;
while (m < 5 ){
printf("Hi, %d hellostu %d \n", m, tablestu[m]);
m++;
}
}