Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Forum » x-Forum » Question

When I tried to store values in allocated memory I keep ge

I am writing a program that prints out the value of cards using a structure. 

I'm a beginner in data structure and I'm trying to advance my knowledge in this area. 

Values of Cards
Face [1 - Ace, 2 - 2, ......, 11 - Jack, 12 - Queen, 13 - King]
Shape [0 - Spades, 1 - Clubs, 2 - Diamonds, 3 - Hearts]
Color [0 - Black, 1 - Red]

I've used the malloc function to allocate memory for 3 cards, which was passed to a pointer name *myCards, with type struct cards.

Code
struct Cards *myCards;
myCards = (struct Cards *)malloc(3 * sizeof(struct Cards));
Code

I am trying to store 3 cards (Queen Spades, 4 Diamonds, Ace Clubs) in the space of the allocated memory, using the pointer myCards but I'm getting an error when I ran the code. 
Code for storing the 3 cards

Code
    *(myCards + 0) = 12, 1;
    *(myCards + 1) = 4, 2;
    *(myCards + 2) = 1, 1;
Code


error(incompatible types when assigning to type 'struct Cards' from type 'int')

My structure

Code
struct Cards {
    int face[13];
    int shape[3];
    int color[1];
}Cards;
Code







Posted by JonathanSimo 2020-08-14 09:53:32

No Ans Posted

Please login to comment

Log In


Ask New Question