I have a menu driven program that should point towards several functions depending on the user's input.
One of the functions is supposed to prompt the user to enter a string and then determine whether or not it is a palindrome.
When the function is called upon it prints the prompt text then immediately states, without any user input, that the string is a palindrome. Could someone take a look and let me know why it is ignoring the input?
Code:
palindrome()
{
char string[20];
int first, last;
printf("Enter a string (max 20 char): ");
fgets(string, 20, stdin);
for (first = 0, last = strlen(string) - 1; first < last; first++, last--)
{
if(string[first] != string[last])
printf("This string is not a palindrome. \n");
}
printf("This string is a palindrome. \n");
}