good day to all, can anyone help me how can my program read if a letter is inputted again it prompts "letter inputted already"? heres my code:

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
    char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char letter;
    int i;
    for(i = 0; i < 26; i++)
    {
    printf("%s\n\n", alphabet);
    printf("Choose a letter: ");
    letter = getchar();

    printf("\n\n");

    for(i = 0; i < 26; i++)
    {
        if (letter == alphabet[i]) 
         {
            alphabet[i] = '_';
            break;   /* This terminates the for() loop */
         }        


    }
     printf("Result: %s\n", alphabet);

     }

}

There are several problems with this. One is that a letter can be input in either upper or lower case. Since you are limiting input to 26 letters (the number of letters in the English alphabet), then you need to convert the letter to upper case to match your array. Second, your logic will not operate properly if the user inputs an underscore since you have already substituted the underscore for valid letters if they were previously input.

There are functions to determine if an input character is an alphabetic character. IE, your logic is simple but convoluted. So, create another character array with 26 slots, and when a valid letter is input, look in that array for the character. If it isn't found, add it to the array, otherwise emit your diagnostic message.

This article has been dead for over six months. Start a new discussion instead.