fork download
  1. #include <stdio.h>
  2.  
  3. int is_palindrome(const char* str) {
  4. const char* last = str + strlen(str) - 1;
  5. while (str < last) {
  6. if (*str++ != *last--) return 0;
  7. }
  8.  
  9. return 1;
  10. }
  11.  
  12. int main(void) {
  13. printf("%d\n", is_palindrome(""));
  14. printf("%d\n", is_palindrome("foo"));
  15. printf("%d\n", is_palindrome("ooffoo"));
  16. printf("%d\n", is_palindrome("..-.."));
  17. printf("%d\n", is_palindrome("lala"));
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
1
0
1
1
0