-
Notifications
You must be signed in to change notification settings - Fork 3
/
card.c
59 lines (52 loc) · 923 Bytes
/
card.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "pokergame.h"
void card_init(Card * aCardPtr, int suit, int rank){
aCardPtr->suit = suit;
aCardPtr->rank = rank;
}
int card_toString(Card * aCardPtr){
if(aCardPtr==NULL)
return -1;
switch(aCardPtr->rank){
case 11:
printf("J");
break;
case 12:
printf("Q");
break;
case 13:
printf("K");
break;
case 14:
printf("A");
break;
default:
printf("%d",aCardPtr->rank);
break;
}
printf(" of ");
switch(aCardPtr->suit){
case 1:
printf("Spades");
break;
case 2:
printf("Hearts");
break;
case 3:
printf("Diamonds");
break;
case 4:
printf("Clubs");
break;
default:
printf("%d",aCardPtr->suit);
break;
}
putchar('\n');
return 0;
}
int card_compare(const void * a, const void * b){
return ((*(Card**)(a))->rank)-((*(Card**)(b))->rank);
}
void card_destroy(Card * aCardPtr){
free(aCardPtr);
}