Posted By

rtperson on 12/02/12


Tagged


Versions (?)

Palindrome Check In C


 / Published in: Haskell
 

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)

  1. bool checkPalindrome(char *number) {
  2. char *begin, *end;
  3. int x;
  4. x = strlen(number) - 1;
  5.  
  6. begin = &number[0];
  7. end = &number[x];
  8.  
  9. for ( ; x >= 0; --x) {
  10. if ( *begin++ != *end--) return false;
  11. }
  12.  
  13. return true;
  14. }

Report this snippet  

You need to login to post a comment.