Code:
#include <stdlib.h>
#include <time.h>
//For suits 1 is Diamond, 2 is Heart, 3 is Club, and 4 is Spade
//For cards 1 is Ace, 11 is Jack, 12 is Queen, and 13 is King
int main() {
char **card, **suit, **matched_card, **matched_suit;
int **matched_count, **matched_pass;
char go='y';
int card_count=52, suit_count=52, match=52, pass=52, i, j, k, a, b, c, d, e, f, g, h, match_count=0,pass_count=1;
card=(char**)calloc(sizeof(char**),card_count);
suit=(char**)calloc(sizeof(char**),suit_count);
matched_card=(char**)calloc(sizeof(char**),card_count);
matched_suit=(char**)calloc(sizeof(char**),suit_count);
matched_count=(int**)calloc(sizeof(int**),match);
matched_pass=(int**)calloc(sizeof(int**),pass);
card[0]="Ace";
card[1]="Two";
card[2]="Three";
card[3]="Four";
card[4]="Five";
card[5]="Six";
card[6]="Seven";
card[7]="Eight";
card[8]="Nine";
card[9]="Ten";
card[10]="Jack";
card[11]="Queen";
card[12]="King";
suit[0]="Diamond";
suit[1]="Heart";
suit[2]="Club";
suit[3]="Spade";
while(!(go=='n')) {
srand(time(NULL));
for(i=1;i<=(52-match_count);i++) {
a=rand()%4;
b=rand()%13;
c=rand()%4;
d=rand()%13;
if((card[b]==card[d])&&(suit[a]==suit[c])) {
++match_count;
for(j=0;j<match_count;j++) {
if(!((card[b]==matched_card[j])||(suit[a]==matched_suit[j]))) {
matched_card[match_count-1]=card[b];
matched_suit[match_count-1]=suit[a];
matched_count[match_count-1]=match_count;
matched_pass[match_count-1]=pass_count;
//printf("%d\n",match_count);
//printf("Match!\n");
}
}
}
}
printf("Only %d matches left, keep going (y or n): ",(52-match_count));
scanf("%c",&go);
printf("%c\n",go);
++pass_count;
}
printf("Match Pass Suit Card\n");
for(k=0;k<52;k++) { //THIS IS THE PROBLEM FOR LOOP
//printf("This works\n");
printf("%6s",matched_count[k]);
printf("%5s",matched_pass[k]);
printf("%10s",matched_suit[k]);
printf("%8s",matched_card[k]);
//printf("%6s%5s%10s%8s\n",matched_count[i],matched_pass[i],matched_suit[i],matched_card[i]);
}
}
Ive looked through all my pointers many times and I cant seem to find where I am going over the memory Ive allocated for it.