一个可以判断字符串是否回文Pallindrome的c程序
1 #include <stdio.h> 2 #include <stdbool.h> 3 #include <string.h> 4 5 bool isPalindromeNumber(const char *string); 6 7 int main(int argc, const char * argv[]) 8 { 9 10 // insert code here... 11 printf("Begin!\n"); 12 13 char *string = "abcccbaa"; 14 bool ret = isPalindromeNumber(string); 15 16 if (ret) { 17 printf("string is palindrome number.\n"); 18 } else { 19 printf("string is not palindrome number.\n"); 20 } 21 22 23 return 0; 24 } 25 26 bool isPalindromeNumber(const char *string) 27 { 28 bool isPNumber = false; 29 30 int i; 31 size_t j; 32 33 i = 0; 34 j = strlen(string) - 1; 35 36 if (strlen(string) < 3) { 37 return false; 38 } 39 40 while ( j-i > 1) { 41 42 if (string[i] == string[j]) { 43 i++; 44 j--; 45 } else { 46 isPNumber = false; 47 break; 48 } 49 50 if (j - i <= 1) { 51 isPNumber = true; 52 } 53 } 54 55 return isPNumber; 56 }