i'm trying to do a biggest card game in c
but i'm reciving some errors that i can't figure out
please help me...

the functions are separeted of the main(project)

i'm receving the error 'incompatible types in assignment' in the function compare card

/*This function compares card1 with card2 and returns 0 if the cards are equals,
-1 if card1 < cadr2 and else 1. The comparison is done considerating the value
absolute of the card. The bigger value is the biggest card. In case of tie (2 or most cards
with the same value), the suit must be verificate, considerating the follow order:
Diamonds < Spades < Hearts < Clubs.

Example: 10 of Diamonds < 10 of Spades < 10 of Hearts < 10 of Clubs
            king of Diamonds >  10 of Clubs */

typedef struct{
        SUIT suit;
        int value;
        }CARD;

typedef struct{
        CARD *cards[52];
        int atual; /*indicates the next card to be withdrawal of the deck*/
        }DECK;
        
typedef struct{
        char name[30];
        CARD hand[3];
        CARD biggest_card;
        int num_victories;
        }PLAYER;

int compare_card(CARD *card1, CARD *card2)
{
    PLAYER players;
    if(card1->valor == card2->valor)
    {
        if(card1->suit < card2->suit)
        {
            players.biggest_card = card2;
            return -1;
        }
        else
        {
            players.biggest_card = card1;
            return 1;
        }
    }
    else
    {
        if(card->value < card2->value)
        {   
            players.biggest_card = card2;
            return -1;
        }
        else
        {
            players.biggest_card = card1;
            return 1;
        }
    }
}

i'm using DevC++

ps: sorry, my english is not very good.

line 30: valar is not a member of CARD. What you want here is value, not valar.

line 32: what is SUIT ? If it is anything other than POD (Plain Old Data) type or an enumeration then the ocmparison on line 32 can't be done like that because you can't compare two structures.

lines 34, 39 and 41. Wrong because card1 and card2 are pointers. But you can do this (see the star) players.biggest_card = *card2;

sorry, i forgot

typedef enum{diamonds, spades, hearts, clubs}SUIT;

can you help me in something else?

i did the shuffle_cards function, but when i print the deck
there are many cards repeat, and missing some cards

what do i do worng?

void shuffle_cards(DECK *deck)
{
     int p1, p2, i;
     CARD *new;
     
     for(i=0; i<50; i++) // shuffle the cards 50 times
     {
             p1 = rand()%51;
             p2 = rand()%51;
             new = deck->cards[p1];
             deck->cards[p1] = deck->cards[p2];
             deck->cards[p2] = new;
             
     }
}

i'm receving the error 'incompatible types in assignment' again, now in the main

the structs are in a file 'declarations.h'
the main is in a file 'main.c'
and the functions are in 3 diferent files 'cards.c', 'deck.c' and 'players.c'
the function 'Withdraw_Card' are in the file 'deck.c'

typedef enum{diamonds, spades, hearts, clubs}SUIT;

typedef struct{
        SUIT suit;
        int value;
        }CARD;

typedef struct{
        CARD *cards[52];
        int atual; /*indicates the next card to be withdrawal of the deck*/
        }DECK;

typedef struct{
        char name[30];
        CARD hand[3];
        CARD biggest_card;
        int num_victories;
        }PLAYER;

main()
{
     int x, j, k, n_players; 
     PLAYER *players
.
.
.

     srand(time(NULL));
     x = rand()%n_players; // draw lots player
     if(x==0)
        x = 1;
     printf("Draw:\n\n");
     printf(" * Begin the game: Player %d\n\n", x);
     printf(" * NAME: %s\n\n", players[x].name);
     printf("____________________________________________________________\n\n");
                       
     for(j=0; j<n_players; (j++)%n_players)  // for each player 
     {
           printf("PLAYER %d:\n", j+1);
           for(k=0; k<3; k++)                         // 3 cards are distributed
           {
                  players[j].hand[k] = Withdraw_Card(&deck);
                  printf("\tcard %d: %d of %d\n\n", k+1, players[j].hand[k].value, players[j].hand[k].naipe);
           }
     }
     printf(" => 3 cards has been ditributed for each player.\n\n\n");

.
.
.
}


/*this function withdraw one card of the deck and increment the variable atual*/
CARD *Withdraw_Card(DECK *deck)
{
      CARD *card;
      deck->cards[deck->atual] = card;
      deck->atual++;
      return card;
}

in lines 34 and 43 i dont have problems, but in line 42 i do

line 37: >> for(j=0; j<n_players; (j++)%n_players) // for each player
That doesn't make sense. what is that mod operator there for?

line 42: deck is undefined

line 42: Withdraw_Card() returns a pointer, so if you want to copy the return value into a non-pointer then you have to dereference it: players[j].hand[k] = *Withdraw_Card(&deck); or this memcpy(&players[j].hand[k], Withdraw_Card(&deck), sizeof(CARD));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.