Code:
int i = 0;
char ch;
printf("Enter a word, no more than 20 alpha characters only, or ? to quit: ");
while ((ch = getchar()) && ch != '\n')
{
if (isalpha(ch))
{
originalString[i] = ch;
i++;
if (i > 20)
{
printf("You entered more than 20 characters. Please try again.\n");
printf("Enter a word, no more than 20 alpha characters only, or ? to quit: ");
fflush(stdin); //only outward buffers can be flushed, is the C Standard.
i = 0;
ch = getchar();
}
}
else //this else goes with the *nearest unelsed if statement*
//not the one you have it left justified for.
{
printf("You entered a non-alpha character. Please try again.\n");
printf("Enter a word, no more than 20 alpha characters only, or ? to quit: ");
fflush(stdin);
i = 0;
ch = getchar();
}
originalString[i] = '\0';
}
I'll run it to be sure, but I believe that is your problem.