#include
//如果是回文,返回1,否则返回0
int foo(const char *pch)
{
const char *pEnd=pch; //pEnd指向字符串头
while(*pEnd !='\0') //将pEnd指针后移,直到字符串尾,即\0字符
pEnd++;
pEnd--; //回退一个,不比较字符'\0'
while(pch
return 0; //如果有两个不等,说明不是回文,返回0
return 1;
}
int main()
{
char *str1 = "abcdefgfedcba";
char *str2 = "abcdefgfedcbax";
if (1 == foo(str1))
{
printf("YES\r\n");
}
else
printf("NO\r\n");
if (1 == foo(str2))
{
printf("YES\r\n");
}
else
printf("NO\r\n");
return 0;
}
#include {
int foo(char *str)
{
char *p=str;
while(*p) p++;
p--;
while(str
if(*p!=*str)
return 0;
p--;
str++;
}
return 1;
}
main()
{
char s[80] ;
printf("Enter a string: ") ;
gets(s) ;
printf("\n\n") ;
puts(s) ;
if(foo(s))
printf("YES\n") ;
else
printf("NO\n") ;
}
int foo(char *str)
{
char* start = str;
char* end = str + strlen(str);
while(start < end)
{
if(*start != *end)
return 0;
start++;
end--;
}
return 1;
}