I am doing a project where i must create a Black Jack simulation. So i started by creating a deck and a draw function. Since there are no strings in C i created two arrays of pointers to use them as a custom-string arrays. The thing is that when i print the card to see its value and suit ,only the first time it prints what expected. The second time is a mess. Can someone explain this to me ? Here is my code
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
char* suit[] = {"Diamonds", "Hearts", "Spades", "Clubs"};
char* facevalue[] = { "Seven", "Eight", "Nine", "Ten", "Jack","Queen", "King", "Ace"};
char* drawCard()
{
char* card[50];
int cardNumber=rand()%8;
int cardColor=rand()%4;
strcpy(card,facevalue[cardNumber]);
char of[]=" of ";
char* xrwma =suit[cardColor];
strncat(card,of,5);
strncat(card,xrwma,8);
return card;
}
int main()
{
srand(time(NULL));
char* c=drawCard();
puts(c);
puts(c);
return 0;
}