srand() should only be called once in your program. Put it early in main.
cardNum is rand() % 13, so it will be 0 to 12, inclusive. So cardNum == 13 will never be true. Your numbers in this section should go from 9 to 12 (Jack is 9).
"rank variable, which is either an int or a char"
Not in C. You need to pick one or the other. Make it a char and set it like so:
Code:
char rank = "23456789TJQKA"[cardNum];
I'm not sure what you mean by "a way to return a char".
If you want to return a char, return a char. Or have you made a double typo and meant "return a card"? I.e., you'd like to return both the rank and suit.
Code:
typedef struct Card {
char rank;
char suit;
} Card;
Card rnd_card(void) {
Card c;
c.rank = 'T';
c.suit = 'H';
return c;
}
Alternatively, you can represent a card as a random int from 0 to 51, inclusive. When you need the suit, just use (ncard / 13), when you want the value use (ncard % 13) (possibly + 2, depending on your purpose).
Code:
#include <stdio.h>
#define CARD_STRING "23456789TJQKA"
#define SUIT_STRING "CDHS"
int print_card(int card) {
printf("%c%c ", CARD_STRING[card % 13], SUIT_STRING[card / 13]);
}
int main(void) {
for (int i = 0; i < 52; i++)
print_card(i);
putchar('\n');
return 0;
}