vendredi 4 novembre 2022

My if statement is not working only the else statement prints in C [duplicate]

I'm trying to build a word guesser where you guess a word from the given choice. The words are stored in an array. The player is losing even though they must win.


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


void guess(int N) {
  int number, guess, numberofguess = 0;
  int myval[] = {"R22", "B3", "R33", "B232", "R12",
                 "B45", "R2", "B12", "R45",  "B32"};
  srand(time(NULL));

  number = rand() % N;
  printf("choose a number "
         "{'R22','B3','R33','B232','R12','B45','R2','B12','R45','B32'}\n");

  char str[20];
  gets(str);
  printf("your guess is %s\n", str);

  if (str == myval[number]) {
    printf("you win\n");
  } else
    printf("you lose\n");

  printf("the number is %s", myval[number]);
}

main() {
  int N = 9;

  guess(N);

  return 0;
}

I want to make the code in such a way when the player enters the code and it matches with the random output the if statement works.




Aucun commentaire:

Enregistrer un commentaire