Hi guys, My name is Leonard E Norwood Jr. I'm a senior at Norfolk State University and a beginning of programming. I'm just working on a small program on my own time to practice. So you're familiar with the playing cards and the logic of dealing a deck with 4 players. I've been working on it for some time, but I think I'm making beginner's mistakes with this program. Take a look:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
#define BOOL int
#define NUM_SUITS 4
#define NUM_RANKS 13
int main(void)
{
BOOL in_hand[NUM_SUITS],[NUM_RANKS] = {FALSE};
int num_cards, rank, suit;
int num_cards = 13;
const char rank_code[] = {'2','3','4','5','6','7','8',
'9','t','j','q','k','a'};
const char suit_code[] = {'c','d','h','s'};
srand( time(NULL));
printf("Your hand :");
while(num_cards > 0) {
suit = rand() % NUM_SUITS;
rank = rand() % NUM_RANKS;
if (!in_hand[suit][rank]) {
in_hand[suit][rank] = true;
num_cards--;
printf(" %c%c", rank_code[rank], suit_code[suit]);
}
}
printf("\n");
return 0;
}
So this is what I got so far. The plan was to make sure I have 52 possible cards out of this array, and make sure to declare them right so once I compile and ran this, up to 4 players display 13 cards of each deck. And Multiple runs makes sure to produce a different deck without duplicates. rand() and srand() are to ensure that each out put is random and not produce to same outputs. However due to how I made this, I got this many error and warnings:
-bash-4.3$ gcc deckOfCardsLNorwood.c
deckOfCardsLNorwood.c: In function `main':
deckOfCardsLNorwood.c:17: error: syntax error before '[' token
deckOfCardsLNorwood.c: At top level:
deckOfCardsLNorwood.c:23: error: syntax error before '(' token
deckOfCardsLNorwood.c:26: error: syntax error before string constant
deckOfCardsLNorwood.c:26: error: conflicting types for 'printf'
deckOfCardsLNorwood.c:26: note: a parameter list with an ellipsis can't match an empt y parameter name list declaration
deckOfCardsLNorwood.c:26: error: conflicting types for 'printf'
deckOfCardsLNorwood.c:26: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
deckOfCardsLNorwood.c:26: warning: data definition has no type or storage class
deckOfCardsLNorwood.c:29: error: initializer element is not constant
deckOfCardsLNorwood.c:29: warning: data definition has no type or storage class
deckOfCardsLNorwood.c:30: error: syntax error before "if"
deckOfCardsLNorwood.c:33: error: syntax error before string constant
deckOfCardsLNorwood.c:33: warning: data definition has no type or storage class
deckOfCardsLNorwood.c:36: error: syntax error before string constant
deckOfCardsLNorwood.c:36: warning: data definition has no type or storage class
-bash-4.3$ cat deckOfCardsLNorwood.c
Oh I almost forgot to add that I'm using PuTTy to practice. PuTTy must have some C89 format or something because when I tried to do this thing words for word off the book and ran it, due to C99 stuff I put in there, it had some errors on it. It seems despite my attempts, I still failed to declare boolean variable designed to make a comparison to make sure the card selected in the "deck" is the same as the card picked to avoid duplicates, arrays NUM_SUITS, NUM_RANK, code_suit, and code_rank. I thought I did, but if the compiler said I didn't then, I didnt. I just need some kind of help fix these errors and get this code running again. If the problem turns out to be the boolean declarations and other things that should have been settled in the beginning, I need to be pointed the right way. I await the help