int main() { char s[1024]; int wins=0; FILE *f = fopen("poker.txt", "rb"); if ( !f ) { perror("poker.txt"); return 1; } while ( fgets(s, 1023, f) != NULL ) { hand h1, h2; int n = read(h1, s); read(h2, s+n+1); if ( p1_wins(h1, h2) ) { printf("p1 wins "); ++wins; } else printf(" "); printf("p1=("); print(h1); score s1 = getscore(h1); printf(") %s (%d) -- ", rankstr(s1.rank), s1.topcard.value); printf("p2=("); print(h2); score s2 = getscore(h2); printf(") %s (%d)\n", rankstr(s2.rank), s2.topcard.value); } printf("p1 wins: %d\n", wins); }
/************************************************************************ * * * Check and print information if it is a Sisheader. * * Return OK or NOT_OK. * * */ static int check_sisfile(char *filename) { Sisheader sisfile; int fd; /* file descriptor */ if ((fd = open(filename,O_RDONLY|O_NDELAY, 0644)) == -1) { fprintf(stderr,"Couldn't open %s for reading\n", filename); exit(1); } if (read(fd, (char *)&sisfile, sizeof(Sisheader)) != sizeof(Sisheader)) { fprintf(stderr,"Couln'd read %s\n", filename); exit(1); } (void)close(fd); if (sisfile.magic_num == (long)SIS_MAGIC) { fprintf(stdout, " %s:\n", filename); fprintf(stdout, " rank:\t %s\n",rankstr(sisfile.rank)); fprintf(stdout, " bit:\t\t %s\n",bitstr(sisfile.bit)); fprintf(stdout, " type:\t %s\n",typestr(sisfile.type)); fprintf(stdout, " fast:\t %d\n", sisfile.fast); fprintf(stdout, " medium:\t %d\n", sisfile.medium); fprintf(stdout, " slow:\t %d\n", sisfile.slow); fprintf(stdout, " hyperslow:\t %d\n", sisfile.hyperslow); fprintf(stdout, " ratio_fast:\t %f\n", sisfile.ratio_fast); fprintf(stdout, " ratio_medium: %f\n", sisfile.ratio_medium); fprintf(stdout, " ratio_slow:\t %f\n", sisfile.ratio_slow); fprintf(stdout, " ratio_hyperslow: %f\n", sisfile.ratio_hyperslow); return(OK); } else return(NOT_OK); /* Not a sisfile */ }