#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
#define MAX_LENGTH_OF_INPUT_WORD 20
#define MAX_ARRAY_SIZE 100000
int main (int argc, char *argv[]) {
char word[MAX_LENGTH_OF_INPUT_WORD];
char palindromeStore[MAX_ARRAY_SIZE];
int scanCount = 0;
while (fgets(word, sizeof(word),stdin)!= NULL) {
word[strlen(word) - 1] = '\0';
// suppose isPalindrome is true
// note: 'i' is a counter that
// will be used later
int isPalindrome = TRUE;
int i = 0;
// checks if strlen(word) is odd or even
// by testing if strlen(word)%2 is 0
if (strlen(word)%2 == 0){
for(i = 0; i <= (strlen(word))/2; i++){
if (word[i] != word[strlen(word) - (i+1)]) {
// contradiction, hence isPalindrome
// is false
isPalindrome = FALSE;
}
}
} else {
for (i = 0; i <= (strlen(word)-1)/2; i++){
if (word[i] != word[strlen(word) - (i+1)]){
isPalindrome = FALSE;
}
}
}
/// palindromeStore
// this generates a store of words which we can
// later print for words that are palindroms
if (isPalindrome == TRUE){
printf("'%s' is a palindrome!\n", word);
word[strlen(word)] = '\n';
strcat(palindromeStore, word);
// this attaches word to palindromeStore, except
// the last character before the null byte is a
// \n so that it'll print out the string of
// palindromeStore with a new line for each word
} else {
printf("'%s' is not a palindrome.\n", word);
}
scanCount++;
printf("This is word: %d\n", scanCount);
}
printf("%s", palindromeStore);
return EXIT_SUCCESS;
}