void evaluate_hand(int Decks[2][5][2], int Hands[2], const char *hNames[]) { int i; for( i = 0; i < 2; i++) { if ((check_flush(Decks, i)) && (check_straight(Decks, i))) { Hands[i] = 9; continue; } else if (check_four(Decks, i)) { Hands[i] = 8; continue; } else if (check_full(Decks, i)) { Hands[i] = 7; continue; } else if (check_flush(Decks, i)) { Hands[i] = 6; continue; } else if (check_straight(Decks, i)) { Hands[i] = 5; continue; } else if (check_three(Decks, i)) { Hands[i] = 4; continue; } else if (check_two_pair(Decks, i)) { Hands[i] = 3; continue; } else if (check_pair(Decks, i)) { Hands[i] = 2; continue; } else Hands[i] = 1; } if (Hands[0] > Hands[1]) printf("HAND 1 WINNER with %s\n ", hNames[Hands[0]-1]); else if (Hands[1] > Hands[0]) printf("HAND 2 WINNER with %s\n", hNames[Hands[1]-1]); else if (getMax(Decks, 0) > getMax(Decks, 1)) printf("HAND 1 WINNER with %s\n ", hNames[Hands[0]-1]); else if (getMax(Decks, 1) > getMax(Decks, 0)) printf("HAND 2 WINNER with %s\n", hNames[Hands[1]-1]); else printf("Split\n"); }
char* check_option(char **in,int n,int which,int type) { char test,*ret=NULL,wasfound=0,ok=1; int i; for (i=1;i<n;i++) { if (in[i] != NULL) { test= (in[i][0] == '-') && (in[i][1] == which); if (test) { wasfound=1; if (type != 'n') { if (strlen(in[i]) > 2) { switch(type) { case 'u': check_unsigned(in[i]+2,which);break; case 'd': check_integer(in[i]+2,which);break; case 'f': check_float(in[i]+2,which);break; case '2': check_two(in[i]+2,which);break; case '3': check_three(in[i]+2,which);break; } if (ret != NULL) free(ret); check_alloc(ret=(char*)calloc(strlen(in[i]+2)+1,(size_t)1)); strcpy(ret,in[i]+2); in[i]=NULL; } else { in[i]=NULL; i++; if (i < n) { if (in[i] != NULL) { switch(type) { case 'u': check_unsigned(in[i],which);break; case 'd': check_integer(in[i],which);break; case 'f': check_float(in[i],which);break; case '2': check_two(in[i],which);break; case '3': check_three(in[i]+2,which);break; case 'o': ok=check_optional(in[i],which);break; } if (ok) { if (ret != NULL) free(ret); check_alloc(ret=(char*)calloc(strlen(in[i])+1,(size_t)1)); strcpy(ret,in[i]); in[i]=NULL; } else { i--; if (ret != NULL) free(ret); ret=NULL; } } } else { if (ret != NULL) { free(ret); ret=NULL; } } } } else { in[i]=NULL; } } } } if (((type == 'o') || (type == 'n')) && (ret == NULL) && wasfound) return ""; if (wasfound && (ret == NULL)) { fprintf(stderr,"The option -%c needs some value. Exiting!\n",which); exit(CHECK_OPTION_C_NO_VALUE); } return ret; }