Palindrome Check In C


/ Published in: C
Save to your folder(s)

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)


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.