I am new to C language and would like to understand the code. The standard input stream is given a string consisting of words with a maximum length of 100 characters. Words consist of Latin characters and are separated by one space. Write to standard output a string containing only palindromes. A palindrome is a word that reads the same in both directions. For example, for input: dad peep aaas. To the exit: dad peep
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void) {
int i = 0;
char word[100];
int ch, bk, fr;
while (EOF != (ch = getchar())) {
if (isspace(ch) != 0) {
if (i > 0) {
fr = 0;
bk = i - 1;
while (word[fr] == word[bk]) {
++fr;
--bk;
}
if (fr < bk)//not palindromes
i = 0;
else {
while (i > 0)
printf("%c", word[--i]);
printf("%c", ch);
}
}
if (ch == '\n')
break;
}
else {
word[i++] = tolower(ch);//check i < sizeof(word)
}
}
}
It is not clear to me how the algorithm selects the words we need. I would like to know this step by step due to my extreme inexperience.