First, you can use isupper
or isalpha
to check for upper case or alphabetic characters.
You get strange characters, because you printf("%c", msg[chk++]);
. You increase chk
, no matter if you inserted a character before.
When you move printf
inside the first if
, it should work as expected
if (isupper(*p)) {
p++;
printf("%c", msg[chk++]);
} else if (*p == '\n')
break;
A small optimization: You can move the comparison in chk_msg
to the for
exit condition
for (i = msg, j--; i < j; i++, j--) {
if (*i != *j)
palindrome = false;
}