C言語筆記試験問題(19)——判断文字列回文


#include 
#include 

int str_test(char *str)
{
    assert(str != NULL);

    char *p_top = str;
    char *p_end;

    while (*++str != '\0')
        ;

    p_end = --str;

    while (p_top <= p_end)
    {
        if (*p_top++ != *p_end--)
            return 0; 
    }

    return 1;
}
int main(int argc, const char *argv[])
{
    char str[] = "abcba";

    printf("%d
", str_test(str)); return 0; }