I am trying to make a deck of cards and minipulate them in 3 files part 1, part 2, and header. In the header I am trying to make the deck so that it would be easy to call up in both part 1 and part 2. In part 1 I am trying to call up all the parts I think would work in C and started on the main body. Calling all the variables and making sure it to get all the cards of the same suit together. I then am trying to shuffle the deck. After that I am trying to sorte the deck so that each of the cards is together with all 4 of their like cards. In part 2, I again called all the variables and put the deck in order. Only this time I made a bit array and zeroed it out. After that I had a loop pick a random number and put the card in that random place as long as the bit array was zero at that spot. However, this is not working at all and I would love any help on what I am doing wrong.
"deck.h" 11 lines, 221 characters
#include <iostream>
int main()
{
for (int CurrentCard = 1; CurrentCard <= 52; CurrentCard++){
typedef enum { clubs, diamonds, hearts, spades} suit_t;
typedef struct
{
unsigned int number : 4;
suit_t suit : 2;
} card_t;
}
"part1.c" 51 lines, 937 characters
#include <stdio.h>
#include <deck.h>
#include <iostream>
#include <stdlib.h>
main()
{
int b = 1;
int c = 1;
char shufflesave[1][];
deck deck[][];
for (int a = 1; a <= 52; a++){
if (a <= 13){
deck[a][].suit_t = 0;
deck[a][].card_t = a;
}
else if (a > 13 && a <= 26){
deck[a][].suit_t = 1;
deck[a][].card_t = a - 13;
}
else if (a > 26 && a <= 39){
deck[a][].suit_t = 2;
deck[a][].card_t = a-26;
}
else{
deck[a][].suit_t = 3;
deck[a][].card_t = a-39;
}
}
for (int shuffle = 0; shuffle <= 52; shuffle++){
int r = 1 + rand() % 51;
shufflesave[][] = deck[b][];
deck[r][] = deck[b][];
shufflesave[1][] = deck[r][];
b++;
}
cout << deck[][];
for (int sort = 0; sort <= 52; sort++){
for (int mult = 1; mult <= 4; mult++){
if (sort >= 1 && sort <= 52){
for (int mult = 1; mult <= 4; mult++){
if (deck[sort][] == sort + "*"){
shufflesave[1][] = deck[mult][];
deck[mult][] = deck[sort][];
deck[sort][] = shufflesave[1][];
}
}
}
}
}
cout << deck[];
}
"part2.c" 46 lines, 743 characters
#include <stdio.h>
#include <deck.h>
int main()
{
int a;
int b;
int c;
b = 0;
bit CardBits[56][];
for (a = 0; a < 52; a++){
CardBits[a][] = 0;
}
int r;
char shuffleSave[1][];
deck deck[][];
int card;
for (card = 1; card <= 52; card++){
if (a <= 13){
deck[card][].suit_t = 0;
deck[card][].card_t = a;
}
else if (a > 13 && a <= 26){
deck[card][].suit_t = 1;
deck[card][].card_t = a - 13;
}
else if (a < 26 && a <= 39){
deck[card][].suit_t = 2;
deck[card][].card_t = a - 26;
}
else{
deck[card][].suit_t = 3;
deck[card][].card_t = a - 39;
)
}
for (c = 0; c <= 52; c++){
r = 1 + rand() %51;
while (CardBits[c][] != 0){
c++;
}
shffleSave[][] = deck[c][];
deck[c][] = deck[r][];
deck[r][] = shuffleSave[][];
CardBits[c][] = 1;
}
cout << deck[][];
}