I am trying to add a letter to an array which I've defined in a for loop. For each time the user inputs something, I would like to decrease "counterSoFar" by 1, and display it. However, "counterSoFar" always decreases by 2 and skip an opportunity for the user to input anything, instead of decreasing "counterSoFar" by 1. I've tried looking through the code multiple times but I still can't figure out why. Please advise.
# include <stdio.h>
# include <ctype.h>
void userInput(char[]);
int main() {
printf("Player 1 please enter a word of up to 12 letters.\n");
char word[13];
scanf("%13s", word);
userInput(word);
}
void userInput(char word[])
{
int n = strlen(word);
for (int i = 0; i < n; i++)
{
word[i] = tolower(word[i]);
}
int checker;
for (int i = 0; i < n; i++)
{
if (isalpha(word[i]))
{
checker = 1;
}
else
{
checker = 0;
printf("Please enter a word without spaces and numbers!\n");
break;
}
}
if (checker == 1)
{
int counterSoFar = 8;
char letter[1];
printf("The word to guess is as follows: \n");
for (int i = 0; i < n; i++)
{
printf("_");
}
int maxTries = 7;
for (int guessCounter = 0; guessCounter < maxTries; guessCounter++)
{
printf("\n");
counterSoFar = counterSoFar - 1;
printf("You have %d tries left!\n\n", counterSoFar);
printf("Player 2 please enter only 1 letter!\n");
scanf("%c", &letter);
char array[13];
for (int c = 0; c < n; c++)
{
if (letter == word[c])
{
array[c] = word[c];
}
else
{
array[c] = '_';
}
}
printf("The current array is %c", array);
}
}
}