Skip to main content
edited body
Source Link
realUser404
  • 1.1k
  • 1
  • 7
  • 15

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • Second one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.

In order to to do that, you should not use the Contains method in order to know if the letter is in the word, but rather parse the array yourself to find where the letter matches.

It could look like this

void CheckInputLetter(array1, array2, letter)
{
    int i = 0;
    while (array1[i] != '\0') //parse the whole array
    {
         if (array1[i] == letter)
             array2[i] = letter;
         i++;
    }
}

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • Second one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.

In order to to that, you should not use the Contains method in order to know if the letter is in the word, but rather parse the array yourself to find where the letter matches.

It could look like this

void CheckInputLetter(array1, array2, letter)
{
    int i = 0;
    while (array1[i] != '\0') //parse the whole array
    {
         if (array1[i] == letter)
             array2[i] = letter;
         i++;
    }
}

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • Second one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.

In order to do that, you should not use the Contains method in order to know if the letter is in the word, but rather parse the array yourself to find where the letter matches.

It could look like this

void CheckInputLetter(array1, array2, letter)
{
    int i = 0;
    while (array1[i] != '\0') //parse the whole array
    {
         if (array1[i] == letter)
             array2[i] = letter;
         i++;
    }
}
added sample code
Source Link
realUser404
  • 1.1k
  • 1
  • 7
  • 15

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • FirstSecond one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.

In order to to that, you should not use the Contains method in order to know if the letter is in the word, but rather parse the array yourself to find where the letter matches.

It could look like this

void CheckInputLetter(array1, array2, letter)
{
    int i = 0;
    while (array1[i] != '\0') //parse the whole array
    {
         if (array1[i] == letter)
             array2[i] = letter;
         i++;
    }
}

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • First one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • Second one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.

In order to to that, you should not use the Contains method in order to know if the letter is in the word, but rather parse the array yourself to find where the letter matches.

It could look like this

void CheckInputLetter(array1, array2, letter)
{
    int i = 0;
    while (array1[i] != '\0') //parse the whole array
    {
         if (array1[i] == letter)
             array2[i] = letter;
         i++;
    }
}
Source Link
realUser404
  • 1.1k
  • 1
  • 7
  • 15

I believe the easy way is to keep 2 char arrays

  • First one contains the word
  • First one contains the first letter and the _ char otherwise

What you display to the player is the second array of course.

When you check if the user guessed correctly, find at which index it was in the 1st array, and replace _ by that letter in the second array at the same index.