字符串回文就是从左到右阅读字符串和从右向左阅读的结果是一样的,就是说字符串是对称的。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
IsReverse(const char *str)
{
if (str == NULL)
return (-1);
int left, right;
left = 0;
right = strlen(str)-1;
while (left < right) {
if (str[left] == str[right])
left++, right--;
else
return (0);
}
return (1);
}
//test IsReverseStr
int
main(int argc, char **argv)
{
if (argc != 2) {
printf("usage: ./a.out testStr\n");
exit(1);
}
int res = IsReverse(argv[1]);
if (res == 1)
printf("true\n");
else if (res == 0)
printf("false\n");
else
printf("argument error\n");
return 0;
}