// broken_wordle.c // // This program should scan in a target word and a guess, then print the // Wordle-style feedback for that guess: // 'G' - the letter is correct and in the correct position // 'Y' - the letter is in the word, but in the wrong position // '.' - the letter is not in the word // // Unfortunately, this code contains a number of errors. // It's your job to fix them, good luck! #include #include #define WORD_LENGTH 5 #define BUFFER_SIZE 20 //////////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE ANY OF THE CODE BELOW HERE // // THE CODE BELOW IS SIMPLY TO ASSIST IN SCANNING IN THE TARGET WORD AND // // THE GUESS. THERE ARE NO BUGS IN THIS SECTION. // //////////////////////////////////////////////////////////////////////////////// int main(void) { char target[BUFFER_SIZE]; char guess[BUFFER_SIZE]; printf("Enter the target word: "); scanf("%s", target); printf("Enter your guess: "); scanf("%s", guess); printf("Scoring your guess...\n"); //////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE ANY OF THE CODE ABOVE HERE // // THE CODE ABOVE IS SIMPLY TO ASSIST IN SCANNING IN THE TARGET WORD AND // // THE GUESS. THERE ARE NO BUGS IN THIS SECTION. // //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////// ONLY EDIT CODE BELOW HERE /////////////////////////// //////////////////////////////////////////////////////////////////////////// char result[WORD_LENGTH + 1]; result[WORD_LENGTH] = '\0'; // Mark every letter that is in the correct position. int i = 0; while (i <= WORD_LENGTH) { if (guess[i] == target[i]) { result[i] = 'G'; } else { result[i] = '.'; } } // Mark every remaining letter that appears somewhere in the word. for (int j = 0; j < WORD_LENGTH; j++) { if (result[j] = '.') { for (int k = 0; k < WORD_LENGTH; k++) { if (guess[j] == target[j]) { result[j] = 'Y'; } } } } printf("%c\n", result); if (strcmp(result, "GGGGG") == 0) { printf("You win!\n"); } return 0; }