-1

I am trying to program poker game in C. I am not allowed to change the function:

void eval_strength(struct hand *h){

 //mycode

}

void eval_players_best_hand(struct player *p){

    int i; 
    p ->best_hand = p->hands[0];
      for(i=0; i <MAX_COMBINATIONS; i++){
         if(eval_strength(p->hands[i])) > p->best_hand){
           p->best_hand = p->hands[i];
       }
     }

Can someone help me fix these errors please!

poker.c: In function ‘eval_players_best_hand’:

poker.c:181:15: error: incompatible types when assigning to type ‘struct hand *’ from type ‘struct hand’

  p->best_hand = p->hands[0];
           ^
poker.c:183:21: error: incompatible type for argument 1 of ‘eval_strength’

  if((eval_strength(p->hands[i])) > p->best_hand){

In the functions void eval_players_best_hand(struct player *p) I am trying to evaluate the strength of the hand, for each hand in the array. Then I have to point best_hand to the strongest hand . eval_strength is another function that will set the hands vector according to its strength.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
dp123
  • 21
  • 5
  • `struct hand *` and `struct hand` are two different types. One is a pointer, the other is not. The two types are not compatible. Now think back to your [beginners books](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) you have read, and think about how you could make a pointer from a value. – Some programmer dude Oct 02 '17 at 12:50
  • I tried : p ->best_hand = (*p->hands[0]); But it gives me invalid unary * error. – dp123 Oct 02 '17 at 12:57
  • 3
    Perhaps you should read more about the `&` operator? Which is usually called the *address-of operator*. – Some programmer dude Oct 02 '17 at 12:59

1 Answers1

1

eval_strength() expects a pointer to struct hands as a parameter. You are attempting to pass to it the actual structure, not the pointer to it.

Thus your if statement should read:

if(eval_strength(&p->hands[i])) > p->best_hand){ 

See the difference?

RobJ
  • 11
  • 2