Save yourself the headaches and make some conversion functions to repesent cards as integers. Example:
Code:
int ch2rank(char chrank) {
switch(toupper(chrank)) {
case 'A': return 1;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case '0': return 10;
case 'J': return 11;
case 'Q': return 12;
case 'K': return 13;
}
return 0;
}
int ch2suit(char chsuit) {
switch(toupper(chsuit)) {
case 'S': return 1;
case 'H': return 2;
case 'D': return 3;
case 'C': return 4;
}
return 0;
}
How would you use the functions? Convert some characters into the appropriate values:
Code:
printf("Enter a card in the format RS (R: rank, S: suit).\n");
char chrank, chsuit;
scanf(" %c %c", &chrank, &chsuit);
int rank = ch2rank(chrank);
int suit = ch2suit(chsuit);
printf("%c%c: --> (%d, %d)\n", chrank, chsuit, rank, suit);
Simply repeat this process for all cards entered. For example, given the input 3c 7d 9h js ad, the output is:
3c: --> (3, 4)
7d: --> (7, 3)
9h: --> (9, 2)
js: --> (11, 1)
ad: --> (1, 3)