1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
char* str1 = "maman";
char str2[] = "reliefpfeiler";
char* begin_str_ptr;
char* end_str_ptr;
int len;
unsigned char is_palindrome;
// First
len = strlen(str1);
begin_str_ptr = str1;
end_str_ptr = (str1 + len - 1);
is_palindrome = 1;
while(is_palindrome && (begin_str_ptr < end_str_ptr)) {
printf("cmp : %c and %c\n", (*begin_str_ptr), (*end_str_ptr));
if ((*begin_str_ptr) != (*end_str_ptr)) {
is_palindrome = 0;
} else { }
++begin_str_ptr;
--end_str_ptr;
}
printf("\"%s\" is%s a palindrome\n", str1, ((is_palindrome)? "": " not"));
// Second
len = strlen(str2);
begin_str_ptr = str2;
end_str_ptr = (str2 + len - 1);
is_palindrome = 1;
while(is_palindrome && (begin_str_ptr < end_str_ptr)) {
printf("cmp : %c and %c\n", (*begin_str_ptr), (*end_str_ptr));
if ((*begin_str_ptr) != (*end_str_ptr)) {
is_palindrome = 0;
}
++begin_str_ptr;
--end_str_ptr;
}
printf("\"%s\" is%s a palindrome\n", str2, ((is_palindrome)? "": " not"));
} |
Partager