sr[10];
sr = strrev(s);
This doesn't even compile - arrays are not assignable. Post real code.
(You need to declare sr
as char *sr
for this to actually compile at all.)
Apart from that, your issue is that strrev()
reverses the string in place, so the two strings will always compare equal (since you're effectively comparing the reversed string with itself). What you have to do is:
superfluously inefficient way: create a copy of the string,
strrev()
that, thenstrcmp()
the original and the copy.Somewhat more optimized approach for non-empty strings:
int ispal(const char *s)
{
const char *p = s + strlen(s) - 1;
while (s < p)
if (*p-- != *s++)
return 0;
return 1;
}