Finalish version, tidied up and rearranged a bit.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <errno.h>
FILE *ptr1, *ptr2, *ptr3;
int filelist;
int crds[3][13][13];
int tots[3];
char face[13]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
char typ[3]={'F','M','P'};
int gg, xx, yy, c1, c2, g1;
char var2[300]="";
int tmp=0;
float freq;
//M 6QUN N
main(argc,argv)
int argc;
char *argv[];
{
if ( (ptr2=fopen("hands2.doc","r")) == NULL) {
puts("file2 does not exist");
exit(2); /* an early file does not exist */
}
if ( (ptr3=fopen("handoutput.txt","w")) == NULL) {
puts("\nCant open output file");
exit(2); /* an early file does not exist */
}
do{ /* for each line in dirfile file */
filelist=fscanf(ptr2,"%[^\n]\n",var2);
if (filelist==-1) break;
// printf("\n hello var2<%s>",var2);
//M 6QUN N
xx=(char)var2[2];
yy=(char)var2[3];
gg=(char)var2[0];
// printf("\n %c %c%c",gg, xx,yy);
switch(xx){
case 'A': c1=12; break;
case 'K': c1=11; break;
case 'Q': c1=10; break;
case 'J': c1=9; break;
case 'T': c1=8; break;
case '9': c1=7; break;
case '8': c1=6; break;
case '7': c1=5; break;
case '6': c1=4; break;
case '5': c1=3; break;
case '4': c1=2; break;
case '3': c1=1; break;
case '2': c1=0; break;
default: printf("\n Invalid card 1");
}
switch(yy){
case 'A': c2=12; break;
case 'K': c2=11; break;
case 'Q': c2=10; break;
case 'J': c2=9; break;
case 'T': c2=8; break;
case '9': c2=7; break;
case '8': c2=6; break;
case '7': c2=5; break;
case '6': c2=4; break;
case '5': c2=3; break;
case '4': c2=2; break;
case '3': c2=1; break;
case '2': c2=0; break;
default: printf("\n Invalid card 2");
}
switch(gg){
case 'P': g1=2; break;
case 'T': g1=2; break;
case '1': g1=0; break;
case '2': g1=0; break;
case '5': g1=0; break;
case 'C': g1=1; break;
case 'M': g1=1; break;
default: printf("\n Invalid game type");
}
(crds[g1][c1][c2])++;
(tots[g1])++;
} while(1);
for(c1=0;c1<13;c1++){
for(c2=c1;c2<13;c2++){
if (c1!=c2) {
for(g1=0;g1<3;g1++){
freq=(float)tots[g1]/(crds[g1][c1][c2] + crds[g1][c2][c1] );
printf("%c Cards %c%c Count %03d Freq %03.0f Perc %3.2f ", typ[g1], face[c1],face[c2], crds[g1][c1][c2], freq, 82.875/freq );
}
printf("\n");
}
if (c1==c2) {
for(g1=0;g1<3;g1++){
freq=tots[g1]/(float)crds[g1][c1][c2];
printf("%c Cards %c%c Count %03d Freq %03.0f Perc %3.2f ", typ[g1], face[c1],face[c2], crds[g1][c1][c2], freq, 221/freq );
}
printf("\n");
}
}
}
fclose(ptr2);
fclose(ptr3);
}
Results:-
Code:
F Cards 22 Count 105 Freq 205 Perc 1.08 M Cards 22 Count 114 Freq 166 Perc 1.33 P Cards 22 Count 212 Freq 221 Perc 1.00
F Cards 23 Count 116 Freq 087 Perc 0.95 M Cards 23 Count 119 Freq 076 Perc 1.09 P Cards 23 Count 314 Freq 083 Perc 1.00
F Cards 24 Count 124 Freq 083 Perc 0.99 M Cards 24 Count 107 Freq 090 Perc 0.92 P Cards 24 Count 267 Freq 087 Perc 0.96
F Cards 25 Count 129 Freq 079 Perc 1.05 M Cards 25 Count 090 Freq 090 Perc 0.93 P Cards 25 Count 262 Freq 090 Perc 0.93
F Cards 26 Count 123 Freq 088 Perc 0.94 M Cards 26 Count 126 Freq 080 Perc 1.03 P Cards 26 Count 308 Freq 081 Perc 1.02
F Cards 27 Count 143 Freq 077 Perc 1.08 M Cards 27 Count 120 Freq 080 Perc 1.03 P Cards 27 Count 262 Freq 087 Perc 0.95
F Cards 28 Count 132 Freq 079 Perc 1.04 M Cards 28 Count 101 Freq 081 Perc 1.03 P Cards 28 Count 297 Freq 080 Perc 1.04
F Cards 29 Count 130 Freq 078 Perc 1.06 M Cards 29 Count 102 Freq 093 Perc 0.89 P Cards 29 Count 285 Freq 083 Perc 1.00
F Cards 2T Count 123 Freq 088 Perc 0.94 M Cards 2T Count 093 Freq 089 Perc 0.93 P Cards 2T Count 287 Freq 085 Perc 0.98
F Cards 2J Count 142 Freq 081 Perc 1.02 M Cards 2J Count 112 Freq 082 Perc 1.01 P Cards 2J Count 264 Freq 088 Perc 0.94
F Cards 2Q Count 135 Freq 079 Perc 1.05 M Cards 2Q Count 118 Freq 082 Perc 1.01 P Cards 2Q Count 276 Freq 079 Perc 1.05
F Cards 2K Count 139 Freq 080 Perc 1.03 M Cards 2K Count 116 Freq 081 Perc 1.03 P Cards 2K Count 295 Freq 081 Perc 1.02
F Cards 2A Count 119 Freq 086 Perc 0.97 M Cards 2A Count 134 Freq 077 Perc 1.08 P Cards 2A Count 292 Freq 082 Perc 1.01
F Cards 33 Count 093 Freq 232 Perc 0.95 M Cards 33 Count 080 Freq 236 Perc 0.94 P Cards 33 Count 206 Freq 227 Perc 0.97
F Cards 34 Count 140 Freq 079 Perc 1.05 M Cards 34 Count 108 Freq 090 Perc 0.92 P Cards 34 Count 294 Freq 080 Perc 1.04
F Cards 35 Count 129 Freq 082 Perc 1.01 M Cards 35 Count 107 Freq 083 Perc 1.00 P Cards 35 Count 259 Freq 091 Perc 0.91
F Cards 36 Count 118 Freq 085 Perc 0.98 M Cards 36 Count 119 Freq 078 Perc 1.06 P Cards 36 Count 260 Freq 083 Perc 1.00
F Cards 37 Count 136 Freq 084 Perc 0.99 M Cards 37 Count 126 Freq 074 Perc 1.11 P Cards 37 Count 273 Freq 079 Perc 1.05
F Cards 38 Count 135 Freq 085 Perc 0.97 M Cards 38 Count 097 Freq 092 Perc 0.90 P Cards 38 Count 267 Freq 089 Perc 0.93
F Cards 39 Count 145 Freq 080 Perc 1.04 M Cards 39 Count 100 Freq 084 Perc 0.98 P Cards 39 Count 286 Freq 080 Perc 1.04
F Cards 3T Count 118 Freq 095 Perc 0.87 M Cards 3T Count 101 Freq 086 Perc 0.96 P Cards 3T Count 297 Freq 081 Perc 1.03
F Cards 3J Count 145 Freq 075 Perc 1.10 M Cards 3J Count 106 Freq 085 Perc 0.97 P Cards 3J Count 287 Freq 083 Perc 1.00
F Cards 3Q Count 129 Freq 090 Perc 0.92 M Cards 3Q Count 113 Freq 088 Perc 0.95 P Cards 3Q Count 265 Freq 084 Perc 0.99
F Cards 3K Count 139 Freq 085 Perc 0.98 M Cards 3K Count 106 Freq 090 Perc 0.93 P Cards 3K Count 272 Freq 084 Perc 0.98
F Cards 3A Count 135 Freq 091 Perc 0.91 M Cards 3A Count 105 Freq 083 Perc 1.00 P Cards 3A Count 275 Freq 082 Perc 1.01
F Cards 44 Count 090 Freq 239 Perc 0.92 M Cards 44 Count 086 Freq 220 Perc 1.01 P Cards 44 Count 236 Freq 198 Perc 1.11
F Cards 45 Count 145 Freq 081 Perc 1.02 M Cards 45 Count 122 Freq 085 Perc 0.97 P Cards 45 Count 273 Freq 086 Perc 0.96
F Cards 46 Count 138 Freq 080 Perc 1.04 M Cards 46 Count 113 Freq 080 Perc 1.03 P Cards 46 Count 271 Freq 083 Perc 0.99
F Cards 47 Count 146 Freq 085 Perc 0.98 M Cards 47 Count 124 Freq 078 Perc 1.07 P Cards 47 Count 289 Freq 078 Perc 1.06
F Cards 48 Count 130 Freq 082 Perc 1.02 M Cards 48 Count 113 Freq 083 Perc 1.00 P Cards 48 Count 267 Freq 087 Perc 0.96
F Cards 49 Count 123 Freq 081 Perc 1.03 M Cards 49 Count 109 Freq 090 Perc 0.93 P Cards 49 Count 277 Freq 085 Perc 0.98
F Cards 4T Count 133 Freq 084 Perc 0.99 M Cards 4T Count 103 Freq 088 Perc 0.94 P Cards 4T Count 269 Freq 081 Perc 1.02
F Cards 4J Count 130 Freq 091 Perc 0.91 M Cards 4J Count 116 Freq 080 Perc 1.03 P Cards 4J Count 272 Freq 088 Perc 0.95
F Cards 4Q Count 136 Freq 086 Perc 0.96 M Cards 4Q Count 116 Freq 090 Perc 0.93 P Cards 4Q Count 262 Freq 085 Perc 0.98
F Cards 4K Count 137 Freq 082 Perc 1.01 M Cards 4K Count 107 Freq 088 Perc 0.94 P Cards 4K Count 274 Freq 083 Perc 0.99
F Cards 4A Count 120 Freq 082 Perc 1.02 M Cards 4A Count 150 Freq 069 Perc 1.20 P Cards 4A Count 269 Freq 084 Perc 0.98
F Cards 55 Count 076 Freq 283 Perc 0.78 M Cards 55 Count 080 Freq 236 Perc 0.94 P Cards 55 Count 204 Freq 230 Perc 0.96
F Cards 56 Count 138 Freq 081 Perc 1.02 M Cards 56 Count 115 Freq 081 Perc 1.02 P Cards 56 Count 313 Freq 079 Perc 1.05
F Cards 57 Count 149 Freq 077 Perc 1.07 M Cards 57 Count 120 Freq 084 Perc 0.99 P Cards 57 Count 295 Freq 079 Perc 1.05
F Cards 58 Count 149 Freq 073 Perc 1.14 M Cards 58 Count 095 Freq 092 Perc 0.90 P Cards 58 Count 284 Freq 085 Perc 0.98
F Cards 59 Count 139 Freq 083 Perc 1.00 M Cards 59 Count 108 Freq 087 Perc 0.95 P Cards 59 Count 256 Freq 084 Perc 0.98
F Cards 5T Count 129 Freq 085 Perc 0.97 M Cards 5T Count 115 Freq 086 Perc 0.97 P Cards 5T Count 290 Freq 078 Perc 1.06
F Cards 5J Count 125 Freq 089 Perc 0.94 M Cards 5J Count 115 Freq 074 Perc 1.12 P Cards 5J Count 273 Freq 085 Perc 0.98
F Cards 5Q Count 147 Freq 077 Perc 1.07 M Cards 5Q Count 115 Freq 080 Perc 1.03 P Cards 5Q Count 302 Freq 078 Perc 1.06
F Cards 5K Count 146 Freq 075 Perc 1.11 M Cards 5K Count 117 Freq 082 Perc 1.01 P Cards 5K Count 291 Freq 080 Perc 1.03
F Cards 5A Count 123 Freq 088 Perc 0.95 M Cards 5A Count 114 Freq 083 Perc 1.00 P Cards 5A Count 294 Freq 080 Perc 1.04
F Cards 66 Count 096 Freq 224 Perc 0.99 M Cards 66 Count 085 Freq 222 Perc 0.99 P Cards 66 Count 225 Freq 208 Perc 1.06
F Cards 67 Count 125 Freq 084 Perc 0.98 M Cards 67 Count 121 Freq 081 Perc 1.03 P Cards 67 Count 300 Freq 081 Perc 1.03
F Cards 68 Count 131 Freq 079 Perc 1.05 M Cards 68 Count 108 Freq 087 Perc 0.96 P Cards 68 Count 274 Freq 086 Perc 0.96
F Cards 69 Count 111 Freq 089 Perc 0.93 M Cards 69 Count 116 Freq 083 Perc 1.00 P Cards 69 Count 284 Freq 081 Perc 1.03
F Cards 6T Count 125 Freq 084 Perc 0.99 M Cards 6T Count 099 Freq 084 Perc 0.99 P Cards 6T Count 296 Freq 080 Perc 1.03
F Cards 6J Count 136 Freq 079 Perc 1.05 M Cards 6J Count 114 Freq 084 Perc 0.99 P Cards 6J Count 273 Freq 082 Perc 1.01
F Cards 6Q Count 129 Freq 077 Perc 1.08 M Cards 6Q Count 104 Freq 095 Perc 0.88 P Cards 6Q Count 287 Freq 086 Perc 0.97
F Cards 6K Count 137 Freq 085 Perc 0.97 M Cards 6K Count 107 Freq 089 Perc 0.93 P Cards 6K Count 266 Freq 083 Perc 0.99
F Cards 6A Count 133 Freq 084 Perc 0.99 M Cards 6A Count 130 Freq 079 Perc 1.05 P Cards 6A Count 268 Freq 081 Perc 1.02
F Cards 77 Count 084 Freq 256 Perc 0.86 M Cards 77 Count 081 Freq 233 Perc 0.95 P Cards 77 Count 231 Freq 203 Perc 1.09
F Cards 78 Count 117 Freq 091 Perc 0.91 M Cards 78 Count 125 Freq 079 Perc 1.05 P Cards 78 Count 238 Freq 092 Perc 0.90
F Cards 79 Count 129 Freq 081 Perc 1.02 M Cards 79 Count 107 Freq 085 Perc 0.98 P Cards 79 Count 273 Freq 081 Perc 1.02
F Cards 7T Count 122 Freq 084 Perc 0.98 M Cards 7T Count 108 Freq 087 Perc 0.96 P Cards 7T Count 285 Freq 081 Perc 1.03
F Cards 7J Count 150 Freq 075 Perc 1.10 M Cards 7J Count 142 Freq 072 Perc 1.15 P Cards 7J Count 315 Freq 077 Perc 1.08
F Cards 7Q Count 126 Freq 082 Perc 1.02 M Cards 7Q Count 113 Freq 081 Perc 1.02 P Cards 7Q Count 278 Freq 081 Perc 1.02
F Cards 7K Count 132 Freq 079 Perc 1.04 M Cards 7K Count 117 Freq 084 Perc 0.99 P Cards 7K Count 283 Freq 085 Perc 0.98
F Cards 7A Count 131 Freq 085 Perc 0.98 M Cards 7A Count 106 Freq 087 Perc 0.95 P Cards 7A Count 286 Freq 086 Perc 0.97
F Cards 88 Count 090 Freq 239 Perc 0.92 M Cards 88 Count 089 Freq 212 Perc 1.04 P Cards 88 Count 194 Freq 241 Perc 0.92
F Cards 89 Count 135 Freq 084 Perc 0.98 M Cards 89 Count 113 Freq 083 Perc 1.00 P Cards 89 Count 280 Freq 081 Perc 1.02
F Cards 8T Count 122 Freq 081 Perc 1.02 M Cards 8T Count 111 Freq 084 Perc 0.99 P Cards 8T Count 254 Freq 082 Perc 1.01
F Cards 8J Count 128 Freq 084 Perc 0.98 M Cards 8J Count 115 Freq 083 Perc 1.00 P Cards 8J Count 294 Freq 080 Perc 1.04
F Cards 8Q Count 143 Freq 083 Perc 1.00 M Cards 8Q Count 113 Freq 086 Perc 0.97 P Cards 8Q Count 294 Freq 084 Perc 0.98
F Cards 8K Count 119 Freq 082 Perc 1.02 M Cards 8K Count 129 Freq 076 Perc 1.09 P Cards 8K Count 281 Freq 083 Perc 1.00
F Cards 8A Count 133 Freq 080 Perc 1.04 M Cards 8A Count 086 Freq 093 Perc 0.89 P Cards 8A Count 288 Freq 082 Perc 1.01
F Cards 99 Count 093 Freq 232 Perc 0.95 M Cards 99 Count 090 Freq 210 Perc 1.05 P Cards 99 Count 201 Freq 233 Perc 0.95
F Cards 9T Count 125 Freq 087 Perc 0.95 M Cards 9T Count 127 Freq 078 Perc 1.06 P Cards 9T Count 282 Freq 085 Perc 0.98
F Cards 9J Count 132 Freq 078 Perc 1.06 M Cards 9J Count 116 Freq 081 Perc 1.03 P Cards 9J Count 322 Freq 080 Perc 1.04
F Cards 9Q Count 114 Freq 090 Perc 0.92 M Cards 9Q Count 103 Freq 083 Perc 1.00 P Cards 9Q Count 269 Freq 084 Perc 0.98
F Cards 9K Count 121 Freq 084 Perc 0.98 M Cards 9K Count 121 Freq 078 Perc 1.07 P Cards 9K Count 260 Freq 086 Perc 0.96
F Cards 9A Count 138 Freq 081 Perc 1.02 M Cards 9A Count 098 Freq 088 Perc 0.94 P Cards 9A Count 285 Freq 080 Perc 1.04
F Cards TT Count 105 Freq 205 Perc 1.08 M Cards TT Count 080 Freq 236 Perc 0.94 P Cards TT Count 230 Freq 204 Perc 1.09
F Cards TJ Count 138 Freq 081 Perc 1.02 M Cards TJ Count 109 Freq 096 Perc 0.86 P Cards TJ Count 259 Freq 084 Perc 0.99
F Cards TQ Count 111 Freq 093 Perc 0.89 M Cards TQ Count 109 Freq 087 Perc 0.96 P Cards TQ Count 283 Freq 081 Perc 1.02
F Cards TK Count 131 Freq 088 Perc 0.94 M Cards TK Count 117 Freq 082 Perc 1.01 P Cards TK Count 250 Freq 090 Perc 0.92
F Cards TA Count 119 Freq 082 Perc 1.01 M Cards TA Count 115 Freq 077 Perc 1.07 P Cards TA Count 284 Freq 084 Perc 0.99
F Cards JJ Count 091 Freq 237 Perc 0.93 M Cards JJ Count 093 Freq 203 Perc 1.09 P Cards JJ Count 206 Freq 227 Perc 0.97
F Cards JQ Count 133 Freq 080 Perc 1.04 M Cards JQ Count 108 Freq 083 Perc 1.00 P Cards JQ Count 266 Freq 086 Perc 0.96
F Cards JK Count 119 Freq 093 Perc 0.89 M Cards JK Count 127 Freq 074 Perc 1.12 P Cards JK Count 268 Freq 085 Perc 0.97
F Cards JA Count 137 Freq 083 Perc 0.99 M Cards JA Count 127 Freq 079 Perc 1.05 P Cards JA Count 291 Freq 084 Perc 0.98
F Cards QQ Count 099 Freq 217 Perc 1.02 M Cards QQ Count 081 Freq 233 Perc 0.95 P Cards QQ Count 198 Freq 236 Perc 0.93
F Cards QK Count 125 Freq 074 Perc 1.12 M Cards QK Count 118 Freq 082 Perc 1.01 P Cards QK Count 290 Freq 082 Perc 1.01
F Cards QA Count 131 Freq 083 Perc 0.99 M Cards QA Count 126 Freq 078 Perc 1.07 P Cards QA Count 303 Freq 081 Perc 1.02
F Cards KK Count 097 Freq 222 Perc 1.00 M Cards KK Count 072 Freq 263 Perc 0.84 P Cards KK Count 205 Freq 228 Perc 0.97
F Cards KA Count 135 Freq 082 Perc 1.02 M Cards KA Count 114 Freq 080 Perc 1.04 P Cards KA Count 284 Freq 081 Perc 1.02
F Cards AA Count 106 Freq 203 Perc 1.09 M Cards AA Count 104 Freq 182 Perc 1.22 P Cards AA Count 226 Freq 207 Perc 1.07
Would be better if I just printed the cards and the 'percentage frequence' above or below the normal value of 1, perhaps.
Note I have added for example AQ to QA as the order does not matter.
Probably would have been better if I started from Ace instead of two.