Over a million developers have joined DZone.

Palindrome Check In C

·
// A palindrome is a string that reads the same both backwards and forwards. Famous examples
// are "Madam I'm Adam" or "Able was I ere I saw Elba". This function checks that a given string
// reads the same backwards and forwards. (requires including stdbool.h)


bool checkPalindrome(char *number) {
    char *begin, *end;
    int x;
    x = strlen(number) - 1;
    
    begin = &number[0];
    end = &number[x];
    
    for ( ; x >= 0; --x) {
        if ( *begin++ != *end--) return false;
    }
    
    return true;
}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}