I have a problem with a code of mine. It gives random errors and I don’t know why.. I’m a newbie to C++ so please bear with me >.>
Here is the code that’s problematic:
while (!IsGameOver) {
struct decktype deck = DeckInit();
struct card card = PickACard(deck);
PrintHand(TextCard(card));
}
The parameter for ‘PrintHand’ causes compilation errors no matter what I do. Here are both the functions.
char *TextCard(struct card &card) {
char str[22];
sprintf(str,"%s of %s (%d)",card_num[card.number],card_type[card.color],card.value);
return str;
}
struct card PrintHand(char &cardtext) {
struct card card;
return card;
}
PrintHand isn’t done yet, but I don’t know how to make it work.. Basically what I want to do is feed a string from TextCard to be used in PrintHand. Could you please help? Much appreciated.
EDIT:
The structure ‘card’ at the moment looks like this.
struct card {
int color;
int number;
int value;
char *hand;
int totalvalue;
};
And the errors are along the lines of “can’t convert something to something”. Sorry I couldn’t be more specific :/
You cannot create a local variable and return it from function. Use malloc or new instead.
I don’t know, what you are trying to do here:
If you want just print text, do this: